n = int(input())
A = list(map(int, input().split()))

res = ans = 0
for i in range(n):
    res += A[i] - 1
    ans += abs(res)
print(ans)