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