from collections import deque



N = int(eval(input()))

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



A.sort(reverse=True)



a = deque(A)



arrival = 1

ans = 0



while arrival < N:

    score = a.popleft()

    if arrival == 1:

        ans += score

        arrival += 1

    else:

        ans += score*min(2, N - arrival)

        arrival += 2



print(ans)
N = int(eval(input()))

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



a.sort()



arrival = 1

ans = 0



while arrival < N:

    score = a.pop()

    if arrival == 1:

        ans += score

        arrival += 1

    else:

        ans += score*min(2, N - arrival)

        arrival += 2



print(ans)
from collections import deque

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
a = deque(A)
arrival = 1
ans = 0
while arrival < N:
    score = a.popleft()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score * min(2, N - arrival)
        arrival += 2
print(ans)

N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
arrival = 1
ans = 0
while arrival < N:
    score = a.pop()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score * min(2, N - arrival)
        arrival += 2
print(ans)

-from collections import deque - -A = list(map(int, input().split())) -A.sort(reverse=True) -a = deque(A) +a = list(map(int, input().split())) +a.sort() -    score = a.popleft() +    score = a.pop()