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

summary = 0

for x in range(n):
    tmp = arr[n - x - 1]
    for i in range(len(arr)):
        if arr[i] != tmp: arr[i] -= 1
    if arr[n - x - 1] > 0:
        summary += arr[n - x - 1]

print(summary)