import heapq

N = int(eval(input()))

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

heap = []

for i in range(N):

    heapq.heappush(heap,-A[i])

if N==2:

    ans = -heapq.heappop(heap)

elif N==3:

    ans = -heapq.heappop(heap)-heapq.heappop(heap)

else:

    ans = 0

    ans = -heapq.heappop(heap)

    if N%2==0:

        for _ in range((N-2)//2):

            a = -heapq.heappop(heap)

            ans += 2*a

    else:

        for _ in range((N-3)//2):

            a = -heapq.heappop(heap)

            ans += 2*a

        a = -heapq.heappop(heap)

        ans += a

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

A = sorted(list(map(int,input().split())),reverse=True)

if N%2==0:

    cnt = A[0]

    for i in range(1,N//2):

        cnt += 2*A[i]

    print(cnt)

else:

    cnt = A[0]

    for i in range(1,N//2):

        cnt += 2*A[i]

    cnt += A[N//2]

    print(cnt)
import heapq

N = int(eval(input()))
A = list(map(int, input().split()))
heap = []
for i in range(N):
    heapq.heappush(heap, -A[i])
if N == 2:
    ans = -heapq.heappop(heap)
elif N == 3:
    ans = -heapq.heappop(heap) - heapq.heappop(heap)
else:
    ans = 0
    ans = -heapq.heappop(heap)
    if N % 2 == 0:
        for _ in range((N - 2) // 2):
            a = -heapq.heappop(heap)
            ans += 2 * a
    else:
        for _ in range((N - 3) // 2):
            a = -heapq.heappop(heap)
            ans += 2 * a
        a = -heapq.heappop(heap)
        ans += a
print(ans)

N = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
if N % 2 == 0:
    cnt = A[0]
    for i in range(1, N // 2):
        cnt += 2 * A[i]
    print(cnt)
else:
    cnt = A[0]
    for i in range(1, N // 2):
        cnt += 2 * A[i]
    cnt += A[N // 2]
    print(cnt)

-import heapq - -A = list(map(int, input().split())) -heap = [] -for i in range(N): -    heapq.heappush(heap, -A[i]) -if N == 2: -    ans = -heapq.heappop(heap) -elif N == 3: -    ans = -heapq.heappop(heap) - heapq.heappop(heap) +A = sorted(list(map(int, input().split())), reverse=True) +if N % 2 == 0: +    cnt = A[0] +    for i in range(1, N // 2): +        cnt += 2 * A[i] +    print(cnt) -    ans = 0 -    ans = -heapq.heappop(heap) -    if N % 2 == 0: -        for _ in range((N - 2) // 2): -            a = -heapq.heappop(heap) -            ans += 2 * a -    else: -        for _ in range((N - 3) // 2): -            a = -heapq.heappop(heap) -            ans += 2 * a -        a = -heapq.heappop(heap) -        ans += a -print(ans) +    cnt = A[0] +    for i in range(1, N // 2): +        cnt += 2 * A[i] +    cnt += A[N // 2] +    print(cnt)