n=int(input()) L=list(map(int,input().split())) m,p,b=sum(L),1,1 while b<=m:p+=1;b+=2*p-1 A=list(range(1,p)) P=A+A[p-3::-1] D=[a-l for a,l in zip(P,L)] x=-sum([i for i in D if i<0]) y=sum([i for i in D if i>0]) print(max(x,y))