a = int(input())
sumsd = 0
n = list(map(int, input().split()))
while n != []:
	maxz = max(n)
	n.pop(len(n)-1)
	sumsd += maxz
	if n == []:
		break					
	for x in range(0, len(n)):
		if n[x-1] == 1:
			n.pop(x-1)
		elif n[x-1] != maxz:
			n[x-1] -= 1
print(sumsd)
			

				