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 _ in range(n)]))