n = int(input()) B = list(map(int, input().split())) cnt = x = 0 for b in B: cnt += abs(x) x += b - 1 print(cnt)