from heapq import *

n = int(eval(input()))

A = [*[-int(x) for x in input().split()]]

heapify(A)

ans = -heappop(A)

for c in range(0, n-2, 2): ans += -heappop(A) * (1<<(c+1 < n-2))

print(ans)

n = int(eval(input()))

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

ans = -A[0]

for i in range(n): ans += A[i//2]

print(ans)

from heapq import *

n = int(eval(input()))
A = [*[-int(x) for x in input().split()]]
heapify(A)
ans = -heappop(A)
for c in range(0, n - 2, 2):
    ans += -heappop(A) * (1 << (c + 1 < n - 2))
print(ans)

n = int(eval(input()))
A = sorted([*list(map(int, input().split()))], reverse=True)
ans = -A[0]
for i in range(n):
    ans += A[i // 2]
print(ans)

-from heapq import * - -A = [*[-int(x) for x in input().split()]] -heapify(A) -ans = -heappop(A) -for c in range(0, n - 2, 2): -    ans += -heappop(A) * (1 << (c + 1 < n - 2)) +A = sorted([*list(map(int, input().split()))], reverse=True) +ans = -A[0] +for i in range(n): +    ans += A[i // 2]