n,*l=list(map(int,open(0).read().split()))

from heapq import *

l.sort()

hq=[-l.pop()]

heapify(hq)

a=0

for _ in range(n-1):

  m=heappop(hq)

  a-=m

  t=-l.pop()

  heappush(hq,t)

  heappush(hq,t)

print(a)
n,*l=list(map(int,open(0).read().split()))

from heapq import *

l.sort()

q=[-l.pop()]

a=0

for _ in range(n-1):

  m=heappop(q)

  a-=m

  t=-l.pop()

  heappush(q,t)

  heappush(q,t)

print(a)
n, *l = list(map(int, open(0).read().split()))
from heapq import *

l.sort()
hq = [-l.pop()]
heapify(hq)
a = 0
for _ in range(n - 1):
    m = heappop(hq)
    a -= m
    t = -l.pop()
    heappush(hq, t)
    heappush(hq, t)
print(a)

n, *l = list(map(int, open(0).read().split()))
from heapq import *

l.sort()
q = [-l.pop()]
a = 0
for _ in range(n - 1):
    m = heappop(q)
    a -= m
    t = -l.pop()
    heappush(q, t)
    heappush(q, t)
print(a)

-hq = [-l.pop()] -heapify(hq) +q = [-l.pop()] -    m = heappop(hq) +    m = heappop(q) -    heappush(hq, t) -    heappush(hq, t) +    heappush(q, t) +    heappush(q, t)