#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long MOD = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n; scanf("%lld", &n); vector y(n); for (ll i = 0; i < n; i++) scanf("%lld", &y[i]); long double sum_x = n * (n - 1) / 2; long double sum_y = 0; long double sum_xy = 0; long double sum_x2 = 0; long double sum_y2 = 0; for (ll i = 0; i < n; i++) { sum_y += y[i]; sum_xy += i * y[i]; sum_x2 += i * i; sum_y2 += y[i] * y[i]; } long double a = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x * sum_x); long double b = (sum_x2 * sum_y - sum_xy * sum_x) / (n * sum_x2 - sum_x * sum_x); long double cost = 0.0; for (ll i = 0; i < n; i++) { long double req = a * i + b; cost += (req - y[i]) * (req - y[i]); } cout << fixed << setprecision(12) << b << " " << a << "\n" << cost << endl; return 0; }