#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N; vector A(N); FOR(i, 0, N){ cin >> A.at(i); } double x_sum = 0; double y_sum = 0; double xy_sum = 0; double xx_sum = 0; // square of x FOR(x, 0, N){ ll y = A[x]; x_sum += x; y_sum += y; xy_sum += x*y; xx_sum += x*x; } double a_upper = N * xy_sum - x_sum * y_sum; double a_lower = N * xx_sum - x_sum * x_sum; double a = a_upper / a_lower; double b_upper = xx_sum * y_sum - xy_sum * x_sum; double b_lower = N * xx_sum - x_sum * x_sum; double b = b_upper / b_lower; cout << setprecision(20); p2(b, a); double cost = 0; FOR(x, 0, N){ double y = A[x]; double new_y = a * x + b; double diff = y - new_y; cost += diff*diff; } p(cost); return 0; }