def minus(v, m):
    for i in range(len(m)):
        if m[i] != v:
            m[i] -= 1

n = int(input())
m = [int(i) for i in input().split()]
m.reverse()
c = 0
for i in range(n):
    v = m[i]
    if v > 0:
        c += v
    minus(v, m)

print(c)