#include #define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++) #define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--) #define ALL(X) (X).begin(),(X).end() #define INF 1000000007 #define LINF 1000000000000000007 typedef long long ll; using namespace std; int main(){ int N; cin >> N; double xy=0,x=0,y=0,x2=0,n=N,cost=0; double a,b,A[N]; FOR(i,0,N){ cin >> A[i]; x += i; x2 += i*i; y += A[i]; xy += i*A[i]; } a = (n*xy - x*y)/(n*x2-x*x); b = (x2*y - xy*x)/(n*x2-x*x); FOR(i,0,N){ cost += pow((A[i]-b-a*i),2); } cout << fixed << setprecision(10) << b << ' ' << a << endl << cost; }