N = int(input()) D = [] B = list(map(int, input().split())) for i in range(N): D.extend([i] * B[i]) ans = 0 for i in range(N): ans += abs(i - D[i]) print(ans)