import heapq

FAST_IO = 1

if FAST_IO:

    import io, sys, atexit

    rr = iter(sys.stdin.read().splitlines()).__next__

    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()



    @atexit.register

    def write():

        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

else:

    rr = raw_input

rri = lambda: int(rr())

rrm = lambda: list(map(int, rr().split()))

rrmm = lambda n: [rrm() for _ in range(n)]



rrn = lambda n: [ rr() for _ in range(n)]



N = rri()

arr = rrm()

arr = sorted(arr)

def solve(N, arr):

    pq = []

    cur1 = arr.pop()

    ans = cur1

    cur2 = arr.pop()

    heapq.heappush(pq, (-cur2, (cur2, cur1)))

    heapq.heappush(pq, (-cur2,(cur1, cur2)))

    while arr:

        neg_max, (start, end) = heapq.heappop(pq)

        ans-=neg_max

        cur = arr.pop()

        heapq.heappush(pq, (-cur, (start, cur)))

        heapq.heappush(pq, (-cur, (cur, end)))

    return ans

print((solve(N, arr)))
n = int(eval(input()))

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

arr.sort(reverse = True)

ptr = 1

s = arr[0]

n-=2

while n:

    s+=arr[ptr]

    n-=1

    if n == 0: break

    s+=arr[ptr]

    n-=1

    ptr+=1

print(s)
import heapq

FAST_IO = 1
if FAST_IO:
    import io, sys, atexit

    rr = iter(sys.stdin.read().splitlines()).__next__
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: list(map(int, rr().split()))
rrmm = lambda n: [rrm() for _ in range(n)]
rrn = lambda n: [rr() for _ in range(n)]
N = rri()
arr = rrm()
arr = sorted(arr)


def solve(N, arr):
    pq = []
    cur1 = arr.pop()
    ans = cur1
    cur2 = arr.pop()
    heapq.heappush(pq, (-cur2, (cur2, cur1)))
    heapq.heappush(pq, (-cur2, (cur1, cur2)))
    while arr:
        neg_max, (start, end) = heapq.heappop(pq)
        ans -= neg_max
        cur = arr.pop()
        heapq.heappush(pq, (-cur, (start, cur)))
        heapq.heappush(pq, (-cur, (cur, end)))
    return ans


print((solve(N, arr)))

n = int(eval(input()))
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ptr = 1
s = arr[0]
n -= 2
while n:
    s += arr[ptr]
    n -= 1
    if n == 0:
        break
    s += arr[ptr]
    n -= 1
    ptr += 1
print(s)

-import heapq - -FAST_IO = 1 -if FAST_IO: -    import io, sys, atexit - -    rr = iter(sys.stdin.read().splitlines()).__next__ -    sys.stdout = _OUTPUT_BUFFER = io.BytesIO() - -    @atexit.register -    def write(): -        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) - -else: -    rr = raw_input -rri = lambda: int(rr()) -rrm = lambda: list(map(int, rr().split())) -rrmm = lambda n: [rrm() for _ in range(n)] -rrn = lambda n: [rr() for _ in range(n)] -N = rri() -arr = rrm() -arr = sorted(arr) - - -def solve(N, arr): -    pq = [] -    cur1 = arr.pop() -    ans = cur1 -    cur2 = arr.pop() -    heapq.heappush(pq, (-cur2, (cur2, cur1))) -    heapq.heappush(pq, (-cur2, (cur1, cur2))) -    while arr: -        neg_max, (start, end) = heapq.heappop(pq) -        ans -= neg_max -        cur = arr.pop() -        heapq.heappush(pq, (-cur, (start, cur))) -        heapq.heappush(pq, (-cur, (cur, end))) -    return ans - - -print((solve(N, arr))) +n = int(eval(input())) +arr = list(map(int, input().split())) +arr.sort(reverse=True) +ptr = 1 +s = arr[0] +n -= 2 +while n: +    s += arr[ptr] +    n -= 1 +    if n == 0: +        break +    s += arr[ptr] +    n -= 1 +    ptr += 1 +print(s)