n=int(input()) B=[int(i) for i in input().split()] C=[] for i,b in enumerate(B): C+=[i]*b print(sum([abs(i-C[i]) for i in range(n)]))