n = int(eval(input()))

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

a.sort(reverse=True)



maxval = a[0]

cc = {maxval: 1}



ans = 0

idx = 0



for i in range(1, n):

    if a[i] in cc:

        cc[a[i]] += 2

    else:

        cc[a[i]] = 2

    cc[maxval] -= 1

    ans += maxval

    if cc[maxval] == 0:

        while 1:

            idx += 1

            if maxval > a[idx]:

                maxval = a[idx]

                break



print(ans)

n = int(eval(input()))

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

a.sort()



ans = 0

for i in range(1, n):

    ans += a[n-int(i/2)-1]

print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
maxval = a[0]
cc = {maxval: 1}
ans = 0
idx = 0
for i in range(1, n):
    if a[i] in cc:
        cc[a[i]] += 2
    else:
        cc[a[i]] = 2
    cc[maxval] -= 1
    ans += maxval
    if cc[maxval] == 0:
        while 1:
            idx += 1
            if maxval > a[idx]:
                maxval = a[idx]
                break
print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(1, n):
    ans += a[n - int(i / 2) - 1]
print(ans)

-a.sort(reverse=True) -maxval = a[0] -cc = {maxval: 1} +a.sort() -idx = 0 -    if a[i] in cc: -        cc[a[i]] += 2 -    else: -        cc[a[i]] = 2 -    cc[maxval] -= 1 -    ans += maxval -    if cc[maxval] == 0: -        while 1: -            idx += 1 -            if maxval > a[idx]: -                maxval = a[idx] -                break +    ans += a[n - int(i / 2) - 1]