#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; pair leastSquaresMethod( const vector &x, const vector &y) { int n = (int)x.size(); double s_x = 0, s_y = 0, s_xy = 0, s_xx = 0; for (int i = 0; i < n; ++i) { s_x += x[i]; s_y += y[i]; s_xy += x[i] * y[i]; s_xx += x[i] * x[i]; } double div = n * s_xx - s_x * s_x; double a = (n*s_xy - s_x * s_y) / div; double b = (s_xx*s_y - s_xy * s_x) / div; return make_pair(a, b); } void solve() { int N; cin >> N; vector Y(N), X(N); rep(i, N) cin >> Y[i]; iota(all(X), 0.0); double b, d; tie(d, b) = leastSquaresMethod(X, Y); cout << b << ' ' << d << endl; double sm = 0; rep(i, N) { double z = b + d * i; sm += (z - Y[i])*(z - Y[i]); } cout << sm << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }