#include using namespace std; pair least_squares(const vector &x, const vector &y) { int n = x.size(); vector xy(n); for (int i = 0; i < n; ++i) xy[i] = 1.0 * x[i] * y[i]; vector x2(n); for (int i = 0; i < n; ++i) x2[i] = 1.0 * x[i] * x[i]; double xsum = accumulate(x.begin(), x.end(), 0.0); double ysum = accumulate(y.begin(), y.end(), 0.0); double xysum = accumulate(xy.begin(), xy.end(), 0.0); double x2sum = accumulate(x2.begin(), x2.end(), 0.0); double au = n * xysum - xsum * ysum; double av = n * x2sum - xsum * xsum; double bu = x2sum * ysum - xysum * xsum; double bv = n * x2sum - xsum * xsum; return {au / av, bu / bv}; } signed main() { ios::sync_with_stdio(false); int N; cin >> N; vector A(N); for (int i = 0; i < N; ++i) cin >> A[i]; vector X(N); iota(X.begin(), X.end(), 0); double a, b; tie(a, b) = least_squares(X, A); vector v(N); v[0] = b; for (int i = 0; i + 1 < N; ++i) v[i + 1] = v[i] + a; double c = 0; for (int i = 0; i < N; ++i) { double x = v[i] - A[i]; c += x * x; } cout << fixed << setprecision(8) << b << ' ' << a << '\n' << ' ' << c << endl; }