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

summary = 0
tmp = 0
prev = -1
offset = 0

for x in range(n):
    print(arr)
    tmp = arr[n - x - 1]
    if tmp - x > 0:
        summary += tmp
        if tmp != prev:
            offset = x
        summary -= offset
    prev = tmp
    arr.pop(n - x - 1)

print(summary)