n = int(input())
a = list(map(lambda x: int(x), input().split(' ')))
money = 0

def binSearch(arr, find, min, max):
    mid = int((min + max) / 2)

    if find == arr[mid]:
        return mid
    if min == max:
        return -1
    
    if find > arr[mid]:
        return binSearch(arr, find, mid, max)
    else:
        return binSearch(arr, find, min, mid)

def searchN(arr, id):
    d = arr[id]
    c = 1 
    lid = id - 1
    while lid >= 0 and d == arr[lid]:
        c += 1
        lid -= 1

    rid = id + 1
    while rid < len(arr) and d == arr[rid]:
        c += 1
        rid += 1
        
    return c

def sumOfAll(n):
    return int(n * ((1 + n) / 2)) - 1

def device(cases):
    global n
    global money


    while len(cases) > 0 and cases[-1] == 0:
        cases.pop(-1)

    if sumOfAll(len(cases) + 1) <= cases[-1] * len(cases):
        money += sumOfAll(len(cases) + 1)
        return []
    money += len(cases)

    cases[-1] -= 1 
    if(cases[-1] == 0):
        cases.pop(-1)
    else:
        t = cases[-1]
        cases[-1] = 0
        cases.append(t)

    if len(cases) == 0:
        return cases
    n -= (cases[0] + 1)
    cases.pop(0)


    return cases

cases = []

a.sort()
for case in range(1, max(a) + 1):
    id = binSearch(a, case, 0, len(a))
    if id == -1:
        cases.append(0)
        continue
    balls = searchN(a, id)
    cases.append(balls)
while n > 0 and len(cases) != 0:
    cases = device(cases)

print(money)