// yukicoder: No.731 等差数列がだいすき // bal4u 2019.8.19 #include #include typedef long long ll; //// 入出力関係 #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } int N; int y[1003]; int main() { int i; ll sx, sx2, sy, sxy; ll bo; double a, b; // y = ax + b double cost, c; sx = sx2 = sy = sxy = 0; N = in(); sx = (ll)N*(N+1)/2, sx2 = sx*(2*N+1)/3; for (i = 1; i <= N; i++) { y[i] = in(); sy += y[i], sxy += i*y[i]; } bo = N*sx2 - sx*sx; a = (double)(N*sxy - sx*sy) / bo; b = (double)(sx2*sy - sxy*sx) / bo; printf("%.15lf %.15lf\n", a+b, a); cost = 0, c = a+b; for (i = 1; i <= N; i++) { cost += (c-y[i])*(c-y[i]); c += a; } printf("%.15lf\n", cost); return 0; }