n = int(input()) *a, = map(int,input().split()) ans = R = 0 acc = a[0] for L in range(n): while R < n and acc < L+1: R += 1 acc += a[R] ans += abs(R-L) print(ans)