Machine Learning

n개의 점이 주어질 때, 두 선분으로 이루어진 연속 조각적 선형 함수를 적합시켜 평균 제곱 오차를 최소화하는 문제입니다.

어려움8기하이분 탐색누적 합구현아직 제출이 없습니다시간 제한4초메모리 제한256 MB

문제

Lately, Byton has found interest in the science describing methods of teaching computers identifying patterns in data and drawing conclusions from them -- the machine learning.

During his research in this field, he had to investigate properties of some complicated function ff. He computed its value in a number of points x_1,x_2,x_nx\_1, x\_2 \dots, x\_n, obtaining results y_1,y_2,,y_ny\_1, y\_2, \dots, y\_n.

He would like to approximate ff by some continuous function gg, composed of two linear parts; formally for some xRx \in \mathbb{R}, gg should be linear for arguments less than xx and linear for arguments greater than xx.

Byton would like to achieve a faithful approximation of ff. He would like to minimize the mean squared error:

\[\frac1n \sum_{i=1}^n (y_i - g(x_i))^2.\]

입력

The first line of the input contains a single integer nn (1n100,0001 \le n \le 100\\,000). Each of the next nn lines contain two integers x_i,y_ix\_i, y\_i (0x_i1,000,0000 \le x\_i \le 1\\,000\\,000, 0y_i10000 \le y\_i \le 1000). The numbers x_ix\_i are pairwise different.

출력

You should print a single real number -- the minimum possible mean squared error he is able to achieve.

Your answer will be accepted if its absolute error does not exceed 11.

힌트

In the first example, the optimal mean squared error is 56\frac56. You can get it by fixing on the left the linear function x2+116-\frac{x}{2} + \frac{11}6 and on the right, the linear function 2x42x-4.

In the second example the minimum mean squared error is 691\frac{6}{91}. The function can be constructed from lines 1613x213\frac{16}{13}x - \frac2{13} and 1613x+9413-\frac{16}{13}x + \frac{94}{13}.