import heapq



N = int(eval(input()))

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

A.sort(reverse=True)

h = [-A[0]]

ans = 0

for i in range(1,N):

    ans -= heapq.heappop(h)

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

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

print(ans)

N = int(eval(input()))

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

A.sort(reverse=True)

AA = []

for i in range(N):

    if i == 0:

        AA.append(A[i])

    else:

        AA.append(A[i])

        AA.append(A[i])

AA.sort(reverse=True)

ans = 0

for i in range(N-1):

    ans += AA[i]

print(ans)

import heapq

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
h = [-A[0]]
ans = 0
for i in range(1, N):
    ans -= heapq.heappop(h)
    heapq.heappush(h, -A[i])
    heapq.heappush(h, -A[i])
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
AA = []
for i in range(N):
    if i == 0:
        AA.append(A[i])
    else:
        AA.append(A[i])
        AA.append(A[i])
AA.sort(reverse=True)
ans = 0
for i in range(N - 1):
    ans += AA[i]
print(ans)

-import heapq - -h = [-A[0]] +AA = [] +for i in range(N): +    if i == 0: +        AA.append(A[i]) +    else: +        AA.append(A[i]) +        AA.append(A[i]) +AA.sort(reverse=True) -for i in range(1, N): -    ans -= heapq.heappop(h) -    heapq.heappush(h, -A[i]) -    heapq.heappush(h, -A[i]) +for i in range(N - 1): +    ans += AA[i]