You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:   the i-th letter occurs in the string no more than a_{i} times;  the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. 


-----Input-----

The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet.

The next line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.


-----Output-----

Print a single integer — the maximum length of the string that meets all the requirements.


-----Examples-----
Input
3
2 5 5

Output
11

Input
3
1 1 2

Output
3



-----Note-----

For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".

Difficulty: EASY
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
import sys
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
for idx in range(1, n):
	if arr[idx - 1] <= arr[idx]:
		arr[idx] = arr[idx - 1] - 1
		if arr[idx] == 0:
			print(sum(arr[:idx]))
			sys.exit()
print(sum(arr))


import re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda x=' ': list(map(int, input().split(x)))
RS = lambda x=' ': input().rstrip().split(x)
mod = int(1000000000.0 + 7)
eps = 1e-06
n = RI()[0]
a = RI()
a.sort(key=lambda x: -x)
ans = a[0]
for i in range(1, n):
	if a[i] >= a[i - 1]:
		a[i] = a[i - 1] - 1
	if a[i] > 0:
		ans += a[i]
print(ans)


n = int(input())
mas = input().split()
mas = [int(x) for x in mas]
mas.sort()
p = mas[-1]
k = p
for i in range(2, n + 1):
	if k < 1:
		break
	if mas[-i] >= k:
		k -= 1
		p += k
	else:
		p += mas[-i]
		k = mas[-i]
print(p)


N = int(input())
a = list(map(int, input().split()))
res = 0
used = set()
for c in sorted(a, reverse=True):
	while c and c in used:
		c -= 1
	if c:
		used.add(c)
		res += c
print(res)


N = int(input())
Size = 0
X = sorted(list(map(int, input().split())), reverse=True)
Min = X[0]
for i in X:
	Size += min(i, Min)
	Min = min(Min, i) - 1
	if Min == 0:
		break
print(Size)


n = int(input())
times = [int(z) for z in input().split()]
times.sort()
times = times[::-1]
res = times[0]
for i in range(1, n):
	times[i] = min(times[i], max(times[i - 1] - 1, 0))
	res += times[i]
print(res)


import math

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def inp(n):
	ls = list(map(int, input().split()))
	return ls

def ans(ls):
	flag = [0] * t
	for i in range(t):
		k = 0
		for j in range(t):
			if i != j and ls[i] == ls[j] and (flag[i] == 0):
				flag[j] += 1 + k
				k += 1
	for i in range(t):
		ls[i] = max(0, ls[i] - flag[i])
t = int(input())
ls = inp(t)
while len(ls) != len(set(ls)):
	o = 0
	for i in ls:
		if i == 0:
			o += 1
	if o + len(set(ls)) == len(ls) + 1:
		break
	ans(ls)
print(max(1, sum(ls)))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	d = []
	for i in range(n):
		while a[i] > -1:
			if a[i] not in d:
				d.append(a[i])
				break
			a[i] -= 1
	print(sum(d))
main()


n = int(input())
a = map(int, input().split(' '))
inf = 1000000001

def f(s, m):
	if s == [] or m == 0:
		return 0
	c = min(s[0], m)
	return c + f(s[1:], c - 1)
print(f(sorted(a, reverse=True), inf))


n = int(input())
mas = list(map(int, input().split()))
for i in range(n):
	while mas.count(mas[i]) > 1 and mas[i] > 0:
		mas[i] -= 1
print(sum(mas))


n = int(input())
a = list(map(int, input().split()))
s = set()
for i in range(n):
	while a[i] in s:
		if a[i] > 0:
			a[i] -= 1
		else:
			break
	s.add(a[i])
ans = sum(s)
print(ans)


input()
counts = [int(i) for i in input().split()]
counts.sort()
length = 0
added = set()
for count in counts[-1::-1]:
	while count in added:
		count -= 1
	if count > 0:
		length += count
		added.add(count)
print(length)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a, reverse=True)
count = 0
prev = None
for x in a:
	if prev != None and prev <= x:
		x = max(prev - 1, 0)
	count += x
	prev = x
print(count)


(_, nums) = (input(), [int(x) for x in input().split(' ')])
nums.sort()
nums.reverse()
result = nums[0]
prev = nums[0]
for n in nums[1:]:
	n = prev - 1 if n >= prev else n
	result += n
	prev = n
	if n == 0:
		break
print(result)


def main():
	input()
	(res, visited) = (0, set())
	for a in map(int, input().split()):
		for a in range(a, 0, -1):
			if a not in visited:
				visited.add(a)
				res += a
				break
	print(res)
main()


n = int(input())
t = list(map(int, input().split()))
f = []
u = 0
for j in t:
	if j not in f:
		u += j
		f.append(j)
	else:
		while True:
			if j - 1 not in f:
				a = max(0, j - 1)
				u += a
				f.append(a)
				break
			else:
				j -= 1
print(u)


n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
arr.reverse()
s = set()
sum = 0
flag = 0
for i in range(n):
	temp = arr[i]
	while temp in s:
		temp = temp - 1
		if temp == 0:
			flag = 1
			break
	sum += temp
	s.add(temp)
	if flag == 1:
		break
print(sum)


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
sum = a[0]
for i in range(1, n):
	while a[i] in a[:i]:
		if a[i] != 0:
			a[i] = a[i] - 1
		else:
			break
	sum += a[i]
print(sum)


n = int(input())
a = sorted([(int(x), i) for (i, x) in enumerate(input().split())], key=lambda x: x[0])
used = set()
u = [0 for i in range(n)]
for l in a:
	(c, i) = l
	while c in used and c > 0:
		c = c - 1
	if c > 0:
		used.add(c)
		u[i] = c
print(sum(u))


n = int(input())
a = list(sorted(map(int, input().split())))
d = {}
u = 0
for e in reversed(a):
	while e in d:
		e -= 1
	if e > 0:
		d[e] = True
		u += e
print(u)


import sys

def main():
	n = int(sys.stdin.readline())
	letter_counts = [int(s) for s in sys.stdin.readline().split()]
	letter_counts.sort()
	word_length = 0
	prev_count = None
	for i in range(1, n + 1):
		current_count = letter_counts[-i]
		if prev_count is None:
			word_length += current_count
		else:
			if prev_count <= current_count:
				current_count = prev_count - 1
			if current_count <= 0:
				break
			word_length += current_count
		prev_count = current_count
	print(word_length)
main()


n = int(input())
l = [int(i) for i in input().split()]
ans = 0
for i in range(n):
	while l.count(l[i]) > 1 and l[i] > 0:
		l[i] -= 1
	ans += l[i]
print(ans)


n = int(input())
l = sorted(map(int, input().split()))[::-1]
m = l[0]
for i in range(1, n):
	if l[i] >= l[i - 1]:
		l[i] = l[i - 1] - 1
for i in range(n):
	if l[i] < 0:
		l[i] = 0
print(sum(l))


n = int(input())
l_n = list(map(int, input().split()))
d = {}
t = 0
for n in l_n:
	while n in d and n > 0:
		n -= 1
	d[n] = ''
	t += n
print(t)


a = int(input())
l = list(map(int, input().split()))
l.sort()
k = l[a - 1] + 1
l.reverse()
sum = 0
for i in l:
	k -= 1
	if i > k:
		i = k
	sum += max(i, 0)
	k = i
print(sum)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	i = n - 2
	while i >= 0:
		if a[i] >= a[i + 1] and a[i] > 0:
			a[i] -= 1
			i += 1
		i -= 1
	print(sum(a))
main()


n = int(input().strip())
a = list(map(int, input().strip().split()))
a.sort(reverse=True)
ans = 0
for i in range(len(a)):
	if a[i] <= 0:
		break
	ans += a[i]
	j = i + 1
	while j < len(a) and a[i] == a[j]:
		a[j] -= 1
		j += 1
print(ans)


n = int(input())
s = set()
for i in map(int, input().split()):
	while i in s and i > 0:
		i -= 1
	s.add(i)
print(sum(s))


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
answer = a[0]
current = a[0]
for i in range(1, len(a)):
	if a[i] >= current:
		current = current - 1
		if current < 0:
			current = 0
	else:
		current = a[i]
	answer += current
print(answer)


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
p = l[n - 1]
k = l[n - 1]
for i in range(n - 2, -1, -1):
	if l[i] >= p:
		if p == 0:
			p = 1
		k = k + p - 1
		p = p - 1
	else:
		p = l[i]
		k = k + l[i]
print(k)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
mi = a[0]
for i in range(1, n):
	if mi == 0:
		a[i] = 0
	elif a[i] >= mi:
		a[i] = mi - 1
	mi = a[i]
print(sum(a))


n = input()
sum = 0
li = sorted(map(int, input().split()))[::-1]
a = max(li)
for i in li:
	if a < 0:
		break
	sum += min(a, i)
	a = min(a, i) - 1
print(sum)


def read_list():
	return [int(i) for i in input().split()]

def new_list(n):
	return [0 for i in range(n)]

def new_matrix(n, m=0):
	return [[0 for i in range(m)] for i in range(n)]

def dump(a, i):
	while i > 0 and a[i] <= a[i - 1]:
		a[i - 1] -= 1
		i -= 1
	return a
n = int(input())
a = read_list()
a.sort()
for i in range(1, n):
	a = dump(a, i)
print(sum([i for i in a if i > 0]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(n - 2, -1, -1):
	a[i] = max(min(a[i], a[i + 1] - 1), 0)
print(sum(a))


n = int(input())
ls = list(map(int, input().split()))
ls.sort(reverse=True)
for i in range(0, n, 1):
	for j in range(i + 1, n, 1):
		if ls[i] == ls[j]:
			ls[j] -= 1
			ls[j] = max(0, ls[j])
print(sum(ls))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = a[0]
b = a[:]
for i in range(1, n):
	t = i - 1
	while t >= 0 and b[i] <= a[t]:
		b[i] -= 1
		t -= 1
	if b[i] > 0:
		ans += b[i]
print(ans)


input()
d = {}
s = 0
for i in map(int, input().split()):
	while i in d and i:
		i -= 1
	d[i] = 1
	s += i
print(s)


(n, a) = (int(input()), input().split())
ss = set()
ans = 0
a = [int(n) for n in a]
for i in a:
	cnt = a.count(i)
	while i in ss and i > 0:
		i -= 1
	ss.add(i)
	ans += i
print(ans)


n = int(input())
a = sorted(map(int, input().split()))
b = [0] * n
b[n - 1] = a[n - 1]
for i in range(n - 2, -1, -1):
	b[i] = max(0, min(b[i + 1] - 1, a[i]))
ans = sum(b)
print(ans)


import sys
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
arr2 = []
for i in range(0, n):
	item = arr[i]
	if item not in arr2:
		arr2.append(item)
	else:
		while item in arr2:
			if item > 0:
				item -= 1
			else:
				break
		arr2.append(item)
print(sum(arr2))


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
for i in range(1, n):
	l[i] = min(l[i - 1] - 1, l[i])
	if l[i] < 0:
		l[i] = 0
print(sum(l))


IL = lambda : list(map(int, input().split()))
IS = lambda : input().split()
I = lambda : int(input())
S = lambda : input()
n = I()
a = IL()
a = sorted(a, reverse=True)
for i in range(1, n):
	if a[i] >= a[i - 1]:
		a[i] = max(a[i - 1] - 1, 0)
print(sum(a))


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
c = l[0]
Sum = 0
for i in range(n):
	c = max(0, min(c, l[i]))
	Sum += c
	c -= 1
print(Sum)


n = int(input())
tab = [int(i) for i in input().split()]
ans = 0
while not max(tab) == 0:
	curMax = max(tab)
	ans += curMax
	tab[tab.index(curMax)] = 0
	for i in range(0, n):
		if tab[i] == curMax:
			tab[i] -= 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
for i in range(1, n):
	if a[n - i - 1] >= a[n - i]:
		a[n - i - 1] -= a[n - i - 1] - a[n - i] + 1
s = 0
for i in range(1, n + 1):
	if a[n - i] > 0:
		s += a[n - i]
	else:
		break
print(s)


n = int(input())
a = sorted(list(map(int, input().split())))
su = a[0]
m = a[0]
k = a[0]
for i in range(1, n):
	if a[i] == k:
		if m > 0:
			while m in a:
				m -= 1
			su += m
			a[i] = m
	else:
		su += a[i]
		m = k = a[i]
print(su)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
(ans, cur) = (0, a[0])
for k in a:
	cur = min(cur, k)
	ans += cur
	cur -= 1
	if cur == 0:
		break
print(ans)


def adjust(x, limit):
	if x == 0:
		return 0
	if x <= limit:
		return x - 1
	return limit
n = int(input())
a = list(map(int, input().split()))
a.sort(key=lambda x: -x)
for i in range(1, n):
	a[i] = adjust(a[i - 1], a[i])
print(sum(a))


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
res = 0
cur = 1001001001
for x in a:
	if cur > x:
		res += x
		cur = x
	else:
		cur = max(cur - 1, 0)
		res += cur
print(res)


n = int(input())
l = list(map(int, input().split()))
while True:
	l.sort()
	for i in range(len(l) - 1):
		if l[i] == l[i + 1]:
			l[i] -= 1
			break
	else:
		break
print(sum([x for x in l if x > 0]))


n = int(input())
ip = list(map(int, input().split()))
op = []
count = 0
for i in ip:
	if i not in op:
		count += i
		op.append(i)
	else:
		for j in range(1, i + 1):
			if i - j not in op:
				count += i - j
				op.append(i - j)
				break
			else:
				continue
print(count)


def f():
	global data
	for i in range(len(data)):
		for j in range(len(data)):
			if data[i] == data[j] and i != j:
				data[i] -= 1
				return True
	return False
n = int(input())
data = list(map(int, input().split()))
help = 0
data.sort()
answer = 0
while f():
	answer = 0
for i in range(n):
	if data[i] > 0:
		answer += data[i]
print(answer)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
ai.reverse()
last_num = ai[0] + 1
ans = 0
for num in ai:
	if last_num == 0:
		break
	if num >= last_num:
		last_num -= 1
	else:
		last_num = num
	ans += last_num
print(ans)


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
freq = defaultdict(int)
arr.sort(reverse=True)
curr = arr[0]
cnt = 0
for item in arr:
	curr = min(curr, item)
	cnt += curr
	curr -= 1
	curr = max(curr, 0)
print(cnt)


n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort()
a.reverse()
k = set()
for i in range(len(a)):
	if a[i] not in k:
		ans += a[i]
		k.add(a[i])
	else:
		while a[i] in k and a[i] > 0:
			a[i] -= 1
		ans += a[i]
		k.add(a[i])
print(ans)


n = int(input())
s = sorted([int(i) for i in input().split()])
NON = []
for i in range(n):
	if s[i] in NON:
		while s[i] in NON and s[i] > 0:
			s[i] -= 1
		NON.append(s[i])
	else:
		NON.append(s[i])
print(sum(s))


n = eval(input())
l = list(map(int, input().split()))
i = 0
l = sorted(l)
while i < n - 1:
	if l[i] == l[i + 1]:
		l[i + 1] -= 1
		i = 0
		l = sorted(l)
	else:
		i += 1
sum = 0
i = 0
while i < n:
	if l[i] > 0:
		sum += l[i]
	i += 1
print(sum)


import sys

def main():
	n = int(input())
	a = list(map(int, input().split()))
	ok = False
	while not ok:
		ok = True
		a.sort()
		for i in range(1, n):
			if a[i] == a[i - 1]:
				a[i] = a[i - 1] - 1
				ok = False
	ans = 0
	for e in a:
		if e > 0:
			ans += e
	print(ans)
main()


n = int(input())
d = [int(i) for i in input().split()]
d = sorted(d, reverse=True)
for i in range(1, len(d)):
	d[i] = max(0, min(d[i - 1] - 1, d[i]))
print(sum(d))


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
length = 0
done = set()
for i in arr:
	if i not in done:
		done.add(i)
		length += i
	else:
		while i in done:
			i -= 1
		if i < 0:
			continue
		else:
			done.add(i)
			length += i
print(length)


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
i = 0
while i < n - 1:
	if l[i] != 0:
		if l[i] <= l[i + 1]:
			l[i + 1] = l[i] - 1
	elif l[i] <= l[i + 1]:
		l[i + 1] = 0
	i += 1
print(sum(l))


n = int(input())
lst = list(map(int, input().split()))
d = {}
lst.sort(reverse=True)
d[lst[0]] = True
s = lst[0]
for i in range(1, n):
	k = lst[i]
	if lst[i] in d and d[lst[i]]:
		while k > 0 and k in d:
			k -= 1
	d[k] = True
	s += k
print(s)


n = input()
n = int(n)
q = input().split()
m = {}
d = []
s = 0
for i in range(n):
	temp = int(q[i])
	if temp not in m:
		m[temp] = 1
		s += temp
	else:
		d.append(temp)
if len(d) > 0:
	d.sort()
	it = len(d) - 1
	while it >= 0:
		x = d[it]
		while x > 0:
			if x not in m:
				s += x
				m[x] = 1
				break
			x -= 1
		it -= 1
print(s)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
a.reverse()
S = set()
for x in a:
	while x in S and x > 0:
		x -= 1
	if x:
		S.add(x)
print(sum(S))


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
check = set()
ans = 0
for i in l:
	x = i
	while x in check:
		x -= 1
	if x < 0:
		continue
	ans += x
	check.add(x)
print(ans)


n = int(input())
a = [int(s) for s in input().split()]
a.sort()
b = 10 ** 9 + 1
sum = 0
for i in range(n - 1, -1, -1):
	if min(a[i], b - 1) < 1:
		break
	sum += min(a[i], b - 1)
	b = min(a[i], b - 1)
print(sum)


import sys
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
sum = arr[0]
for i in range(1, n):
	if arr[i] >= arr[i - 1]:
		arr[i] = 0 if arr[i - 1] - 1 < 0 else arr[i - 1] - 1
	sum += arr[i]
print(sum)


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
tot = l[0]
cur = l[0]
for i in range(1, n):
	new = min([cur - 1, l[i]])
	tot += new
	cur = new
	if cur <= 1:
		break
print(tot)


size = int(input())
counts = [int(x) for x in input().split()]
counts.sort(reverse=True)
for i in range(1, size):
	while counts.count(counts[i]) > 1 and counts[i] != 0:
		counts[i] = counts[i] - 1
print(sum(counts))


n = int(input())
arg = sorted(list(map(lambda x: int(x), input().split())))
tmp = arg[-1]
sum = tmp
for i in range(n - 2, -1, -1):
	if arg[i] < tmp:
		tmp = arg[i]
		sum += tmp
	else:
		tmp -= 1
		if tmp < 0:
			break
		sum += tmp
print(sum)


(n, a, s, v) = (int(input()), sorted(map(int, input().split()), reverse=True), set(), 0)
for ai in a:
	while ai and ai in s:
		ai -= 1
	s.add(ai)
	v += ai
print(v)


n = input()
a = [int(each) for each in input().split()]
a.sort(reverse=True)
len0 = len(a)
res = a[0]
for i in range(1, len0):
	if a[i] > a[i - 1] - 1:
		a[i] = a[i - 1] - 1
		if a[i] == 0:
			break
	res += a[i]
print(res)


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
p = []
i = 0
while i < n:
	k = l[i]
	m = 1
	while m == 1:
		if k == 0:
			m = 0
		elif (k in p) == True:
			k = k - 1
		elif (k in p) == False:
			p.append(k)
			m = 0
	i = i + 1
j = sum(p)
print(j)


n = int(input())
i = 0
a = [int(i) for i in input().split()]
seen = {}
a.sort()
for i in range(0, n - 1):
	if a[i] == a[i - 1]:
		a[i] -= 1
	while a[i] != 0 and a[i] in seen:
		a[i] -= 1
	seen[a[i]] = 1
i = n - 1
while a[i] != 0 and a[i] in seen:
	a[i] -= 1
seen[a[i]] = 1
print(sum(a))


from sys import stdin, stdout
import math

def calculate(N, AI):
	mxlen = sum(AI)
	AX = list()
	for val in AI:
		val = int(val)
		if not val in AX:
			AX.append(val)
			continue
		while True:
			val = val - 1
			if val <= 0:
				break
			if not val in AX:
				AX.append(val)
				break
	milen = sum(AX)
	return min(milen, mxlen)
n = stdin.readline().rstrip()
ai = list([int(x) for x in stdin.readline().rstrip().split()])
ans = calculate(n, ai)
stdout.write(str(ans) + '\n')


n = int(input())
s = list(map(int, input().split()))
s.sort()
s.reverse()
k = s[0] - 1
answer = s[0]
for i in range(1, n):
	if k <= s[i]:
		answer += k
		k -= 1
	else:
		answer += s[i]
		k = s[i] - 1
	if k < 0:
		break
print(answer)


n = int(input())
last = float('inf')
l = 0
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in a:
	m = max(min(last, i), 0)
	l += m
	last = m - 1
print(l)


__author__ = 'Admin'
n = int(input())
m = list(map(int, input().split()))
m.sort()
m.reverse()
ans = m[0]
for i in range(1, n):
	if m[i] >= m[i - 1] and m[i - 1] > 0:
		m[i] = m[i - 1] - 1
	elif m[i - 1] == 0:
		m[i] = 0
	ans += m[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort(key=None, reverse=True)
res = a[0]
for i in range(1, n):
	while a[i] >= a[i - 1]:
		a[i] -= 1
	if a[i] > 0:
		res += a[i]
print(res)


n = int(input())
a = list(map(int, input().split(' ')))
done = set()
nb = 0
for x in a:
	while x > 0:
		if not x in done:
			done.add(x)
			nb += x
			break
		else:
			x -= 1
print(nb)


n = int(input())
a = list(map(int, input().split()))
ans = []
for i in a:
	b = i
	while b > 0:
		if b not in ans:
			ans.append(b)
			break
		else:
			b -= 1
print(sum(ans))


def f():
	input()
	a = list(map(int, input().split(' ')))
	a.sort()
	t = 10 ** 9 + 1
	r = 0
	for i in reversed(a):
		t = i if i < t else t - 1
		if t == 0:
			break
		r += t
	print(r)
f()


n = int(input())
L = list(map(int, input().split(' ')))
L.sort(reverse=True)
s = L[0]
p = L[0]
for i in range(1, len(L)):
	c = L[i]
	while c >= p:
		c -= 1
	if c < 0:
		break
	s += c
	p = c
print(s)


n = int(input())
data = list(map(int, input().split()))
answer = 0
for i in range(n):
	if data.count(data[i]) == 1:
		answer += data[i]
	else:
		while data[i] > 0:
			if data.count(data[i]) == 1:
				answer += data[i]
				break
			else:
				data[i] -= 1
print(answer)


n = int(input())
arr = input().split()
a = []
arr = [int(x) for x in arr]
arr.sort(reverse=True)
num = []
while arr:
	if arr[0] not in num:
		num.append(arr.pop(0))
	elif arr[0] > 0:
		arr[0] -= 1
	else:
		num.append(arr.pop(0))
print(sum(num))


n = int(input())
arr = list(map(int, input().split()))
numbers = sorted(arr)
carr = []
count = 0
for i in range(len(numbers)):
	a = numbers[i]
	while a > 0:
		if a in carr:
			a -= 1
		else:
			carr.append(a)
			count += a
			a = 0
print(count)


n = int(input())
line = [int(x) for x in input().split()]
line.sort(reverse=True)
line.append(0)
s = 0
for i in range(n):
	s += line[i]
	if line[i] <= line[i + 1]:
		line[i + 1] = line[i] - 1
	if line[i] <= 0:
		break
print(s)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
c = l[0]
for i in range(1, n):
	while l[i] in l[:i] and l[i] > 0:
		l[i] -= 1
	c += l[i]
print(c)


n = int(input())
s = input()
s = s.split()
a = []
for i in range(n):
	a.append(int(s[i]))
su = 0
d = {}
a.sort(reverse=True)
for i in range(len(a)):
	if a[i] not in d:
		su += a[i]
		d[a[i]] = 1
	else:
		t = a[i] - 1
		while t >= 1 and t in d:
			t -= 1
		su += t
		d[t] = 1
print(su)


n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)[::-1]
t = a[0] + 1
s = 0
for i in a:
	if t > i:
		s += i
		t = i
	else:
		t -= 1
		s += max(t, 0)
print(s)


n = int(input())
c = list(map(int, input().split()))
ret = set()
for x in c:
	for y in range(x, -1, -1):
		if y not in ret:
			ret.add(y)
			break
print(sum(ret))


n = int(input())
a = list(reversed(sorted(list(map(int, input().split())))))
s = set()
for i in a:
	if i in s:
		while i in s and i > 0:
			i -= 1
		s.add(i)
	else:
		s.add(i)
print(max(max(a), sum(s)))


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	print(solver(a))

def solver(L):
	L.sort(reverse=True)
	total = 0
	current = L[0] + 1
	for i in range(len(L)):
		if L[i] >= current:
			current -= 1
			if current <= 0:
				break
		else:
			current = L[i]
		total += current
	return total
main()


n = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
x = set()
res = 0
for i in reversed(sorted(a)):
	while i > 0:
		if i in x:
			i -= 1
		else:
			res += i
			x.add(i)
			break
print(res)


n = int(input())
l = list(map(int, input().split()))
l.sort()
ll = []
for i in l:
	while i > 0 and i in ll:
		i -= 1
	ll.append(i)
print(sum(ll))


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(n):
	val = l[i]
	while val > 0 and val in l[:i]:
		val -= 1
	l[i] = val
	ans += val
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = 0
x = max(a)
for i in range(n):
	if x < 0:
		break
	c = c + min(x, a[i])
	x = min(x, a[i]) - 1
print(c)


N = int(input())
ans = 0
used = set()
for c in sorted([int(x) for x in input().split()], reverse=True):
	while c > 0 and c in used:
		c -= 1
	ans += c
	used.add(c)
print(ans)


n = int(input())
mas = [int(i) for i in input().split()]
d = {}
otv = 0
for i in range(n):
	if mas[i] not in d:
		otv += mas[i]
		d[mas[i]] = 1
	else:
		mas[i] -= 1
		while True:
			if mas[i] > 0:
				if mas[i] not in d:
					otv += mas[i]
					d[mas[i]] = 1
					break
				else:
					mas[i] -= 1
			else:
				break
print(otv)


n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = set()
for i in a:
	sz = len(b)
	while len(b) == sz and i > 0:
		b.add(i)
		i -= 1
print(sum(list(b)))


n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = [A[0]]
for i in range(1, n):
	if A[i] < ans[-1]:
		ans.append(A[i])
	else:
		ans.append(max(0, ans[-1] - 1))
print(sum(ans))


n = int(input())
s = list(map(int, input().split()))
k = 0
s.sort()
for i in range(1, len(s)):
	if s[i] == s[i - 1] and s[i] > 0:
		s[i - 1] = s[i - 1] - 1
	s.sort()
	for i in range(1, len(s)):
		if s[i] == s[i - 1] and s[i] > 0:
			s[i - 1] = s[i - 1] - 1
			s.sort()
			for i in range(1, len(s)):
				if s[i] == s[i - 1] and s[i] > 0:
					s[i - 1] = s[i - 1] - 1
					s.sort()
					for i in range(1, len(s)):
						if s[i] == s[i - 1] and s[i] > 0:
							s[i - 1] = s[i - 1] - 1
for i in range(0, len(s)):
	k = k + s[i]
print(k)


import math
n = int(input(''))
a = input('').split(' ')
b = []
for i in range(n):
	b.append(int(a[i]))
a = []
for i in range(n):
	ma = max(b)
	j = 0
	for z in range(n):
		if b[z] == ma:
			b[z] = 0
			j += 1
	for k in range(j):
		a.append(ma)
for i in range(n - 1):
	if a[i] == a[i + 1] or a[i] <= a[i + 1]:
		a[i + 1] = a[i] - 1
s = 0
for i in range(n):
	if a[i] > 0:
		s += a[i]
print(s)


n = int(input())
string = input()
numbers = list(map(int, string.split()))
numbers = sorted(numbers[::-1])
values = []
b = 0
for x in numbers:
	a = x
	while a in values and a != 0:
		a -= 1
	values.append(a)
	b += a
print(b)


n = int(input())
m = list(map(int, input().split()))
m.sort(reverse=True)
ans = m[0]
last = m[0]
for i in range(1, len(m)):
	last = max(min(last - 1, m[i]), 0)
	ans += last
print(ans)


def main():
	n = int(input())
	xs = sorted(map(int, input().split(' ')), reverse=True)
	prev = xs[0] + 100
	s = 0
	for x in xs:
		if x >= prev:
			x = prev - 1
		if x == 0:
			return s
		prev = x
		s += prev
	return s
print(main())


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
line.sort(reverse=True)
for i in range(1, n):
	line[i] = max(0, min(line[i - 1] - 1, line[i]))
print(sum(line))


n = int(input())
nombres = []
rec = 0
tot = 0
nbr = input()
nbr = nbr.split(' ')
for x in range(0, n):
	a = int(nbr[x])
	while a in nombres and a != 0:
		a -= 1
	tot += a
	nombres.append(a)
print(tot - rec)


n = int(input())
a = list(sorted(map(int, input().split()), reverse=True))
for i in range(n - 1):
	a[i + 1] = max(0, min(a[i] - 1, a[i + 1]))
print(sum(a))


n = int(input())
a = list(map(int, input().split()))
for j in range(n):
	a.sort()
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			a[i] = a[i] - 1
		if a[i] < 0:
			a[i] = 0
print(sum(a))


n = int(input())
Letter = list(map(int, input().split()))
Letter.sort()
ans = 0
while len(Letter) != 0:
	L = len(Letter) - 1
	ans += Letter[L]
	while L != 0 and Letter[L - 1] == Letter[len(Letter) - 1]:
		Letter[L - 1] -= 1
		if Letter[L - 1] == 0:
			del Letter[L - 1]
		L -= 1
	del Letter[len(Letter) - 1]
	Letter.sort()
print(ans)


a = int(input())
b = list(map(int, input().split(' ')))
b.sort()
b.reverse()
for i in range(1, len(b)):
	if b[i] >= b[i - 1]:
		b[i] = b[i - 1] - 1
amor = 0
for i in b:
	if i > 0:
		amor += i
print(amor)


def main():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	for i in range(1, n):
		while l.index(l[i]) != i:
			l[i] -= 1
	answer = 0
	for e in l:
		if e > 0:
			answer += e
	print(answer)
main()


from sys import stdin, stdout
n = stdin.readline()
ais = [int(x) for x in stdin.readline().split()]
res = []
su = 0
for item in ais:
	cur = item
	while cur in res and cur > 0:
		cur = cur - 1
	res.append(cur)
	su = su + cur
stdout.write(str(su))


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = arr[0]
pre = arr[0]
for i in range(1, len(arr)):
	while arr[i] != 0 and arr[i] >= arr[i - 1]:
		arr[i] -= 1
	ans += arr[i]
print(ans)


n = input()
a_in = list(map(int, input().split()))
a = list(reversed(sorted(a_in)))
prev = 1000000001
ans = 0
for c in a:
	if c >= prev:
		c = prev - 1
	if c <= 0:
		break
	ans += c
	prev = c
print(ans)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	n = int(input())
	a = sorted(list(map(int, input().split())), reverse=True)
	for i in range(1, n):
		if a[i] >= a[i - 1]:
			a[i] = max(a[i - 1] - 1, 0)
	print(sum(a))
for _ in range(1):
	solve()


from string import *
n = int(input())
a = list(map(int, input().split()))
s = list(ascii_lowercase)[:n]
res = ''
ans = 0
cnt = 0
a.sort()
while 1:
	ans = 0
	for i in range(n):
		x = a.count(a[i])
		if x > 1:
			a[i] -= min(x - 1, a[i])
	for i in range(n):
		ans += a[i]
	if cnt == ans:
		break
	cnt = ans
print(ans)


n = [int(word) for word in input().split()]
a = [int(word) for word in input().split()]
a.sort()
a.reverse()
bound = a[0] + 1
s = 0
for x in a:
	if x < bound:
		s += x
		bound = x
	else:
		bound -= 1
		if bound <= 0:
			break
		s += bound
print(s)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
a = reversed(a)
ans = 0
prev = 1000000001
for num in a:
	num = max(min(num, prev - 1), 0)
	prev = num
	ans += num
print(ans)


from collections import Counter
n = int(input())
soma = 0
cont = 0
c = list(map(int, input().split()))
counter = Counter(c)
while len(set(c)) != len(c):
	for i in range(len(c)):
		if i >= len(c):
			break
		counter[c[i]] -= 1
		cont = counter[c[i]]
		if c[i] - cont > 0:
			counter[c[i] - cont] += 1
		c[i] -= cont
		if c[i] <= 0:
			c.remove(c[i])
			i -= 1
for x in c:
	soma += x
print(soma)


import sys
n = int(input())
ar = list(map(int, input().split()))
ar.sort(reverse=True)
(ans, x) = (ar[0], ar[0])
for i in range(1, n):
	if x <= ar[i]:
		x -= 1
	else:
		x = ar[i]
	if x <= 0:
		break
	ans += x
print(ans)


R = lambda : map(int, input().split())
n = int(input())
a = sorted(list(R()), reverse=True)
s = set()
t = 0
l = 10 ** 19
for ai in a:
	if ai < l:
		t += ai
		l = ai
	elif l == 1:
		break
	else:
		t += l - 1
		l -= 1
print(t)


input()
l = sorted(list(map(int, input().split())))
while True:
	if len(l) == len(set(l)):
		break
	for i in range(len(l) - 1, 0, -1):
		if l[i] == l[i - 1]:
			l[i] -= 1
			if not l[i]:
				del l[i]
			break
	l.sort()
print(sum(l))


def make_s(lst):
	while True:
		lst.sort()
		for i in range(len(lst) - 1):
			if lst[i] == lst[i + 1]:
				lst[i] -= 1
				break
		else:
			break
	return sum([x for x in lst if x > 0])
n = int(input())
a = [int(i) for i in input().split()]
print(make_s(a))


a = int(input())
current = [int(x) for x in input().split()]
current.sort(reverse=True)
d = dict()
res = 0
for i in range(a):
	maxx = current[i]
	temp = maxx
	while temp in d:
		temp -= 1
	res += temp
	d[temp] = True
	if temp == 1:
		break
print(res)


n = int(input())
l = list(map(int, input().rstrip().split()))
l.sort(reverse=True)
last = l[0]
for i in range(1, n):
	if l[i] >= last:
		if last > 0:
			l[i] = last - 1
			last -= 1
		else:
			l[i] = 0
	else:
		last = l[i]
print(sum(l))


readInts = lambda : list(map(int, input().split()))
n = int(input())
a = readInts()
last = 10 ** 9 + 1
sum = 0
for k in reversed(sorted(a)):
	last = max(0, min(last - 1, k))
	sum += last
print(sum)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
last = a[0]
for i in range(1, len(a)):
	last = min(a[i], last - 1)
	if last == 0:
		break
	ans += last
print(ans)


n = int(input())
ar = list(map(int, input().split()))
ar.sort(reverse=True)
s = ar[0]
for i in range(1, n):
	if ar[i] >= ar[i - 1]:
		ar[i] = max(ar[i - 1] - 1, 0)
	s += ar[i]
print(s)


clist = {}
n = int(input())
alist = map(int, input().split())
for a in alist:
	while a > 0 and a in clist.keys():
		a -= 1
	clist[a] = a
sum = 0
for i in clist.keys():
	sum += i
print(sum)


n = int(input())
a = sorted(map(int, input().split()))[::-1]
for x in range(1, n):
	if a[x] >= a[x - 1]:
		a[x] = max(0, a[x - 1] - 1)
print(sum(a))


n = int(input())
ar = list(map(int, input().split()))
ar = sorted(ar, reverse=True)
used = set()
total = 0
for i in range(len(ar)):
	el = ar[i]
	while el in used and el > 0:
		el -= 1
	if el > 0:
		total += el
		used.add(el)
print(total)


n = int(input())
sLine = input()
sSplit = sLine.split()
v = []
for s in sSplit:
	v.append(int(s))
v.sort()
nSum = 0
nLast = 10 ** 9 + 1
for i in v[::-1]:
	if i >= nLast:
		nLast -= 1
		nLast = max(0, nLast)
	else:
		nLast = i
	nSum += nLast
print(nSum)


n = int(input())
a = [int(i) for i in input().split(' ')]
cnum = set([])
for i in range(n):
	if a[i] not in cnum:
		cnum.add(a[i])
	else:
		for j in range(a[i] - 1, -1, -1):
			if j not in cnum:
				cnum.add(j)
				break
a = list(cnum)
s = 0
for i in a:
	s += i
print(s)


n = int(input())
ar = list(map(int, input().split()))
ar.sort(reverse=True)
a = set()
s = ar[0]
for i in range(1, n):
	ar[i] = min(ar[i - 1] - 1, ar[i])
	if ar[i] < 0:
		ar[i] = 0
print(sum(ar))


n = int(input())
num = [int(x) for x in input().split()]
num.sort(reverse=True)
num[0] += 1
now = num[0]
for x in range(len(num)):
	if num[x] >= now:
		now -= 1
		num[x] = now
	else:
		now = num[x]
	if num[x] == 0:
		num = num[:x]
		break
print(sum(num))


n = int(input(''))
lst = list(map(int, input().split()))
lst.sort()
c = 0
for k in range(n + 1):
	for items in lst:
		lst.remove(items)
		if items in lst:
			lst[lst.index(items)] = lst[lst.index(items)] - 1
		lst.append(items)
for items in lst:
	if items > 0:
		c = c + items
print(c)


class CodeforcesTask624BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.alphabet = []

	def read_input(self):
		self.n = int(input())
		self.alphabet = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.alphabet.sort()
		mx = self.alphabet.pop(-1)
		len_cnt = mx
		while self.alphabet:
			adding = self.alphabet.pop(-1)
			if adding < mx:
				mx = adding
			else:
				mx = max(0, mx - 1)
			len_cnt += mx
		self.result = str(len_cnt)

	def get_result(self):
		return self.result
Solution = CodeforcesTask624BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
rng = [int(t) for t in input().split()]
ans = 0
while len(rng) != 0:
	mx = max(rng)
	if mx <= 0:
		break
	ans += mx
	rng.remove(mx)
	for i in range(len(rng)):
		if rng[i] == mx:
			rng[i] -= 1
print(ans)


n = int(input())
A = sorted(map(int, input().split()), reverse=True)
for i in range(1, n):
	if A[i - 1] <= A[i]:
		A[i] = max(0, A[i - 1] - 1)
print(sum(A))


import os
import sys
import random
li = []
n = int(input())
li = list(map(int, input().split()))
ans = []
for i in li:
	while i in ans and i > 0:
		i -= 1
	ans.append(i)
print(sum(ans))


input()
(r, v) = (0, set())
for a in map(int, input().split()):
	for b in range(a, 0, -1):
		if b not in v:
			v.add(b)
			r += b
			break
print(r)


n = int(input())
data = list(map(int, input().split()))
data.sort()
high = data[-1]
ret = 0
for i in range(n - 1, -1, -1):
	chosen = min(data[i], high)
	ret += max(chosen, 0)
	high = chosen - 1
print(ret)


n = int(input())
L = [int(x) for x in input().split()]
L.sort()
L = L[::-1]
ans = 0
dis = L[0] + 1
for i in L:
	ans += max(0, min(dis, i))
	dis = min(dis, i) - 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
sorted(a)
s = 0
for i in range(n):
	h = a[i]
	k = True
	for j in range(i):
		if h == a[j] and k:
			k = False
	if k:
		s += h
	else:
		j = i - 1
		while j >= 0 and h > 0:
			if h == a[j]:
				h -= 1
				j = i
			j -= 1
		if h >= 0:
			s += h
		a[i] = h
print(s)


from sys import stdin as fin
n = int(fin.readline())
abc = tuple(map(int, input().split()))
cnt = set()
result = 0
for sym in abc:
	while sym and sym in cnt:
		sym -= 1
	result += sym
	cnt.add(sym)
print(result)


n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(n):
	if A[i] in ans:
		for j in range(A[i] - 1, 0, -1):
			if j not in ans:
				ans.append(j)
				break
	else:
		ans.append(A[i])
print(sum(ans))


n = input()
v = input().split()
v = map(int, v)
v = list(v)
oc = {}
s = 0
for (i, vi) in enumerate(v):
	while oc.get(vi, 0) and vi > 0:
		vi -= 1
	oc[vi] = oc.get(vi, 0) + 1
	s += vi
print(s)


n = int(input())
a = [*map(int, input().split())]
d = {}
a.sort(reverse=True)
count = 0
for i in a:
	if d.get(i) == None:
		count += i
		d[i] = 1
	else:
		while True:
			i -= 1
			if i < 0:
				break
			if d.get(i) == None:
				d[i] = 1
				count += i
				break
print(count)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 0
while i < n - 1:
	if a[i] <= a[i + 1]:
		a[i + 1] = a[i] - 1
	if a[i + 1] == 0:
		break
	i += 1
print(sum(a[:i + 1]))


n = int(input())
l = input().split()
for i in range(n):
	l[i] = int(l[i])
l.sort()
i = n - 1
s = 0
while i >= 0:
	if i == n - 1:
		temp = l[i]
		s += temp
		i -= 1
		continue
	if temp == 0:
		break
	if temp <= l[i]:
		s += temp - 1
		temp -= 1
	else:
		s += l[i]
		temp = l[i]
	i -= 1
print(s)


INF = float('inf')
n = int(input())
numbers = sorted(list(map(int, input().split())))[::-1]
cnt = 0
last = INF
for c in numbers:
	cnt += min(last - 1, c)
	last = min(last - 1, c)
	if not last:
		break
print(cnt)


n = int(input())
a = list(map(int, input().split()))
used = set()
reversed(sorted(a))
i = 0
while i < n:
	if a[i] == 0:
		i += 1
	elif a[i] not in used:
		used.add(a[i])
		i += 1
	else:
		a[i] -= 1
print(str(sum(a)))


n = int(input())
k = [int(x) for x in input().split()]
for i in range(n - 1):
	if k[i + 1:].count(k[i]) > 0:
		fl = True
		q = 1
		while fl:
			if k.count(k[i] - q) == 0:
				fl = False
			else:
				q = q + 1
		for j in range(i + 1, n):
			if k[j] == k[i] and k[j] - q >= 0:
				k[j] = k[j] - q
			if k[j] - q < 0 and k[j] == k[i]:
				k[j] = 0
print(sum(k))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr = arr[::-1]
ans = [arr[0]]
for i in range(1, n):
	if arr[i] < ans[-1]:
		ans.append(arr[i])
	else:
		ans.append(max(0, ans[-1] - 1))
print(sum(ans))


n = int(input())
a = list(map(int, input().split()))[:n]
for i in range(len(a)):
	while a.count(a[i]) > 1 and a[i] > 0:
		if a[i] < 0:
			break
		a[i] = a[i] - 1
bh = sum(a)
print(bh)


n = int(input())
a = [int(x) for x in input().split()]
occ = set()
a.sort(reverse=True)
for i in range(len(a)):
	while a[i] in occ and a[i] > 0:
		a[i] -= 1
	occ.add(a[i])
print(sum(a))


n = input()
c = list(map(int, input().split()))
s = set()
answer = 0
c.sort(reverse=True)
for number in c:
	while number > 0:
		if number in s:
			number -= 1
		else:
			s.add(number)
			answer += number
			break
print(answer)


def findSame(a):
	notFound = True
	res = -1
	for i in range(1, len(a)):
		curA = a[0:i]
		if notFound:
			if a[i] in curA and a[i] != 0:
				notFound = False
				res = i
	return res
n = input()
ai = list(map(int, input().split()))
modif = ai
inx = findSame(modif)
while inx > 0:
	modif[inx] -= 1
	inx = findSame(modif)
print(sum(modif))


n = int(input())
l = sorted([int(i) for i in input().split()], reverse=True)
l1 = [0] * n
l1[0] = l[0]
s = l[0]
for i in range(1, n):
	k = min(l[i], l1[i - 1] - 1)
	s += k
	l1[i] = k
	if k == 0:
		break
print(s)


n = int(input())
s = input().split()
s = [int(i) for i in s]
answer = 0
s.sort(reverse=True)
used = []
for i in range(n):
	if s[i] not in used:
		answer += s[i]
		used.append(s[i])
	else:
		while s[i] in used and s[i] > 0:
			s[i] -= 1
		if s[i] == 0:
			continue
		else:
			answer += s[i]
			used.append(s[i])
print(answer)


n = int(input())
arr = [int(x) for x in input().split(' ')]
arr = sorted(arr, reverse=True)
curr_max = arr[0]
ans = arr[0]
for i in range(1, n):
	arr[i] = min(curr_max - 1, arr[i])
	if arr[i] <= 0:
		break
	ans += arr[i]
	curr_max = arr[i]
print(ans)


def main():
	n = int(input())
	nums = [int(i) for i in input().split()]
	print(sol2(nums))

def test():
	N = 10000
	import random
	for i in range(N):
		nums = []
		n = 24
		for j in range(n):
			nums.append(random.randrange(1, 1000000000.0))
		ans2 = sol2(nums)
	print('Completed')

def sol1(_nums):
	nums = reversed(sorted(_nums))
	top = None
	s = 0
	for num in nums:
		if top == 0:
			break
		if top is None:
			top = num
			s += num
			continue
		if num == top:
			s += num - 1
			top -= 1
		elif num < top:
			s += num
			top = num
	return s

def sol2(nums):
	s = 0
	used = []
	for num in nums:
		n = num
		while n in used and n > 0:
			n -= 1
		used.append(n)
		s += n
	return s
main()


n = int(input())
x = list(map(int, input().split()))
x.sort()
sett = set()
ans = 0
for i in range(n):
	if x[i] not in sett:
		ans += x[i]
		sett.add(x[i])
	else:
		while x[i] in sett:
			x[i] -= 1
		sett.add(x[i])
		if x[i] > 0:
			ans += x[i]
print(ans)


N = int(input())
letters = list(map(int, input().split()))
letters.sort()
lennow = 0
for i in range(len(letters) - 2, -1, -1):
	letters[i] = max(0, min(letters[i + 1] - 1, letters[i]))
print(sum(letters))