335_F. Buy One, Get One Free
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.

Input

Input will begin with an integer n (1 ≤ n ≤ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109.

Output

Print the minimum cost to acquire all the pies.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

6
3 4 5 3 4 5


Output

14


Input

5
5 5 5 5 5


Output

25


Input

4
309999 6000 2080 2080


Output

314159

Note

In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free.

In the second test case you have to pay full price for every pie.
```python
#https://codeforces.com/problemset/problem/335/F

h = [i for i in range(500001)]
t = [i for i in range(500001)]
ans = 0
len = 0
nw = 0
tot = 0
cnt = 0
a = []

def work(x):
    y = x >> 1
    while y and h[y] > h[x]:
        tmp = h[x]
        h[x] = h[y]
        h[y] = tmp
        x = y
        y = x >> 1

def pop():
    global len
    h[1] = h[len]
    len -= 1
    x = 1
    y = 2
    if y < len and h[y + 1] < h[y]:
        y += 1
    while y <= len and h[y] < h[x]:
        tmp = h[x]
        h[x] = h[y]
        h[y] = tmp
        x = y
        y = x << 1
        if y < len and h[y + 1] < h[y]:
            y += 1

def solve():
    global cnt, len, tot, nw, a
    n = int(input())

    a = list(map(int, input().split()))
    # print(a)

    ans = sum(a)

    a.sort(reverse = True)

    a.insert(0, -1)
    # print(a)

    for i in range(1, n + 1):
        if not nw:
            nw = a[i]
            tot = 1
        else:
            if nw > a[i]:

                tot -= 1
                cnt += 1
                t[cnt] = a[i]

                if not tot:
                    nw = 0
            else:
                tot += 1
                if tot >= 2 and len and h[1] < a[i] * 2:
                    if h[1] < a[i]:
                        cnt += 1
                        t[cnt] = a[i]
                        cnt += 1
                        t[cnt] = a[i]
                    else:
                        cnt += 1
                        t[cnt] = h[1]
                        cnt += 1
                        t[cnt] = a[i] * 2 - h[1]
                    pop()
                    tot -= 2
                    if not tot:
                        nw = 0
        if i == n or a[i + 1] != a[i]:
            if nw == a[i] and len and h[1] < a[i]:
                pop()
                cnt += 1
                t[cnt] = a[i]
            for j in range(1, cnt + 1):
                len += 1
                h[len] = t[j]
                work(len)
            cnt = 0
    for i in range(1, len + 1):
        ans -= h[i]
    print(ans)

solve()
```