N = int(input())
B = list(map(int,input().split()))

hoge = 0
ans = 0
for i in B:
    hoge -= 1
    hoge += i
    ans += abs(hoge)

print(ans)