#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b linearApproximation(vector> v) { int n = v.size(); double xy = 0; rep(i, 0, n) xy += v[i].first * v[i].second; double x = 0; rep(i, 0, n) x += v[i].first; double y = 0; rep(i, 0, n) y += v[i].second; double xx = 0; rep(i, 0, n) xx += v[i].first * v[i].first; double a = (n * xy - x * y) / (n * xx - x * x); double b = (xx * y - xy * x) / (n * xx - x * x); return { a,b }; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(i, 0, N) cin >> A[i]; vector> v; rep(i, 0, N) v.push_back({ i, A[i] }); double a, b; tie(a, b) = linearApproximation(v); printf("%.10f %.10f\n", b, a); double c = 0; rep(i, 0, N) { double y = a * i + b; double d = y - A[i]; c += d * d; } printf("%.10f\n", c); }