from collections import deque

n = int(eval(input()))

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

# print(n)

# print(A)



A.sort(reverse=True)



# print(A)



q = deque([A[0]])

B = []

for a in A[1:]:

    x = q.popleft()

    B.append(x)

    q.append(a)

    q.append(a)

# print(q)

# print(B)

print((sum(B)))

from collections import deque

eval(input())

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

A.sort(reverse=True)

q = deque([A[0]])

P = []

for a in A[1:]:

    p = q.popleft()

    P.append(p)

    q.append(a); q.append(a)

print((sum(P)))

from collections import deque

n = int(eval(input()))
A = [*list(map(int, input().split()))]
# print(n)
# print(A)
A.sort(reverse=True)
# print(A)
q = deque([A[0]])
B = []
for a in A[1:]:
    x = q.popleft()
    B.append(x)
    q.append(a)
    q.append(a)
# print(q)
# print(B)
print((sum(B)))

from collections import deque

eval(input())
A = [*list(map(int, input().split()))]
A.sort(reverse=True)
q = deque([A[0]])
P = []
for a in A[1:]:
    p = q.popleft()
    P.append(p)
    q.append(a)
    q.append(a)
print((sum(P)))

-n = int(eval(input())) +eval(input()) -# print(n) -# print(A) -# print(A) -B = [] +P = [] -    x = q.popleft() -    B.append(x) +    p = q.popleft() +    P.append(p) -# print(q) -# print(B) -print((sum(B))) +print((sum(P)))