#K41547. Taco: Minimizing Total Perpendicular Distance

    ID: 26889 Type: Default 1000ms 256MiB

Taco: Minimizing Total Perpendicular Distance

Taco: Minimizing Total Perpendicular Distance

You are given N houses on a two-dimensional plane with coordinates \((x_i, y_i)\). Your task is to determine the optimal road (a straight line) such that the total perpendicular distance from all houses to this line is minimized. The perpendicular distance from a point \((x,y)\) to the line \(y = mx + b\) is given by

\(\frac{|y - (mx+b)|}{\sqrt{1+m^2}}\)

When \(N = 1\), the answer is trivially 0. For \(N > 1\), one common strategy is to use linear regression to obtain the best fit line. In this problem, if the variance in \(x\) coordinates (i.e. \(\sum (x_i-x_{mean})^2\)) equals zero, then the points are collinear vertically and the answer is defined as 0.0.

Your output should be the minimal total distance formatted to six decimal places.

inputFormat

The first line contains an integer \(N\) denoting the number of houses.

The next \(N\) lines each contain two integers, representing the coordinates \(x_i\) and \(y_i\) of a house.

outputFormat

Print a single line containing the minimum possible total perpendicular distance from all houses to the optimal road. The result should be formatted to six decimal places.

## sample
1
1 2
0.000000

</p>