N=int(input()) B=[] for i,b in enumerate(map(int,input().split())): B+=[i]*b ans=sum(abs(i-j) for i,j in zip(B,range(N))) print(ans)