n개의 점이 주어질 때, 두 선분으로 이루어진 연속 조각적 선형 함수를 적합시켜 평균 제곱 오차를 최소화하는 문제입니다.
어려움8기하이분 탐색누적 합구현아직 제출이 없습니다시간 제한4초메모리 제한256 MBLately, 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 f. He computed its value in a number of points x_1,x_2…,x_n, obtaining results y_1,y_2,…,y_n.
He would like to approximate f by some continuous function g, composed of two linear parts; formally for some x∈R, g should be linear for arguments less than x and linear for arguments greater than x.
Byton would like to achieve a faithful approximation of f. 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 n (1≤n≤100,000). Each of the next n lines contain two integers x_i,y_i (0≤x_i≤1,000,000, 0≤y_i≤1000). The numbers x_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 1.
In the first example, the optimal mean squared error is 65. You can get it by fixing on the left the linear function −2x+611 and on the right, the linear function 2x−4.

In the second example the minimum mean squared error is 916. The function can be constructed from lines 1316x−132 and −1316x+1394.
