n = int(input())
s = list(map(int, input().split()))
count = 0
for i in range(n-1, -1, -1):
    count += s[i]
    for j in range(i):
        s[j] = s[j] if s[j]==s[i] else 1 if s[j]==1 else s[j]-1
print(count)