n = int(input())
A = list(map(int, input().split()))
elem = A[-1]
kol = 0
otv = elem
for i in range(2, n + 1):
    if A[-i] == elem:
        otv += elem - kol
    else:
        if A[-i] - (i - 1) <= 0:
            break
        elem = A[-i]
        kol = i - 1
        otv += elem - kol
print(otv)