n = int(input())
balls = list(map(int, input().split()))
res = 0
while balls:
    cur = balls[-1]
    res += cur
    balls.pop(-1)
    balls = list(map(lambda x: x-1 if (x != cur and x > 0) else x, balls))
print(res)
