n=int(input()) b=list(map(int,input().split())) y=[] for i in range(n): y+=[i]*b[i] print(sum(abs(y[i]-i) for i in range(n)))