The chalky smell of a black board is something that will always remind us of those long days spent sitting in our desks taking notes instead of playing outside. If we think about it, life is just a mere blink of an eye in terms of time. But time is a relative thing. sighed our math teacher as he approached a picture of the class picture we took at the beginning of the year. He stood there for a while glaring at the picture... then as usual, he strolled back to his desk and pulled out a shiny new math book. He flipped through the first couple of pages and suddenly stopped.
Let's see who can solve this one...
You are given N number of points. Find a function of the format f(x)=a*x+b
for which ∑((y[i]-f(x[i]))^2)
is minimal, where x[i]
and y[i]
are coordinates for the point i
.
Input
N
, the number of points is on the first line. The next N
lines are occupied by pairs of numbers which represent the coordinates of each point. Output
On the first line will be the minimum cost, with 10-3 decimal precision, on the only line.Constraints
1 ≤ N ≤ 1000
-100 000 ≤ x[i], y[i] ≤ 100 000
The output result is considered correct if and only if the diference between your result and the correct one is less then or equal to 1e-3.
Sample
Input | Output |
---|---|
9 60 136 69 198 66 194 64 140 54 93 67 172 59 116 65 174 63 145 | 1093.66860465 |
7 1975 30.663 1980 37.995 1985 42.815 1990 49.951 1995 54.177 2000 60.502 2005 65.199 | 3.50440143 |