#yuki731 import numpy as np n=int(raw_input()) l=np.array(map(float,raw_input().split())) a,b=np.polyfit(np.array(range(n)),l,1) res=0 for i in xrange(n): res+=(l[i]-b-a*i)**2 print res