import sys

from collections import deque



input = sys.stdin.readline



N = int(eval(input()))

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



A.sort(reverse=True)



deq = deque([A[0]])

ans = 0



for x in A[1:]:

    ans += deq.popleft()

    deq.append(x)

    deq.append(x)



print(ans)

import sys



input = sys.stdin.readline



N = int(eval(input()))

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



A.sort(reverse=True)

ans = 0



for i in range(1, N):

    ans += A[i // 2]



print(ans)

import sys
from collections import deque

input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
deq = deque([A[0]])
ans = 0
for x in A[1:]:
    ans += deq.popleft()
    deq.append(x)
    deq.append(x)
print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
for i in range(1, N):
    ans += A[i // 2]
print(ans)

-from collections import deque -deq = deque([A[0]]) -for x in A[1:]: -    ans += deq.popleft() -    deq.append(x) -    deq.append(x) +for i in range(1, N): +    ans += A[i // 2]