def linier_fitting(permulation): n = len(permulation) x=y=xy=xx=0 for i in range(n): xy+=(i+1) * permulation[i] x+=(i+1) y+=permulation[i] xx+=(i+1)**2 d1=n*xy-x*y n1=n*xx-x**2 d2=xx*y-xy*x n2=n*xx-x**2 cross=d1/n1 intercept=d2/n2 #傾きがcross,切片がintercept = 等差数列の交差がcross,初項がintercept+cross return (cross,intercept) def abs_diff_pow(permulation,cross_diff,intercept): diff_sum=0.0 for i in range(len(permulation)): diff_sum+=( permulation[i] - ((i+1)*cross_diff+intercept) )**2 return diff_sum num = int(input()) permulation=list(map(float,input().split())) coeff=linier_fitting(permulation) cross=coeff[0] intercept=coeff[1] init_term=cross+intercept print(init_term,cross) diff_sum=abs_diff_pow(permulation,cross,intercept) print(diff_sum)