N = int(eval(input()))

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

A.sort()

ans = A[-1]

i = N-1

N -= 2

while N:

    i -= 1

    for _ in range(2):

        N -= 1

        ans += A[i]

        if N<=0: break

print(ans)
N = int(eval(input()))

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

A.sort()

if N==2:

    print((max(A)))

    exit()



ans = A.pop()

n = N-2

while A:

    a = A.pop()

    for _ in range(2):

        n -= 1

        ans += a

        if n==0:

            print(ans)

            exit()
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ans = A[-1]
i = N - 1
N -= 2
while N:
    i -= 1
    for _ in range(2):
        N -= 1
        ans += A[i]
        if N <= 0:
            break
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
if N == 2:
    print((max(A)))
    exit()
ans = A.pop()
n = N - 2
while A:
    a = A.pop()
    for _ in range(2):
        n -= 1
        ans += a
        if n == 0:
            print(ans)
            exit()

-ans = A[-1] -i = N - 1 -N -= 2 -while N: -    i -= 1 +if N == 2: +    print((max(A))) +    exit() +ans = A.pop() +n = N - 2 +while A: +    a = A.pop() -        N -= 1 -        ans += A[i] -        if N <= 0: -            break -print(ans) +        n -= 1 +        ans += a +        if n == 0: +            print(ans) +            exit()