from collections import deque



n = int(eval(input()))

a = sorted(map(int, input().split()), reverse=True)



ans, cnt = 0, deque([a[0]])

for i in a[1:]:

    ans += cnt.popleft()

    cnt.extend([i,i])

print(ans)

n = int(eval(input()))

a = sorted(map(int, input().split()), reverse=True)



ans, que, cnt = 0, [a[0]], 0

for i in a[1:]:

    ans += que[cnt]

    que += [i, i]

    cnt += 1

print(ans)

from collections import deque

n = int(eval(input()))
a = sorted(map(int, input().split()), reverse=True)
ans, cnt = 0, deque([a[0]])
for i in a[1:]:
    ans += cnt.popleft()
    cnt.extend([i, i])
print(ans)

n = int(eval(input()))
a = sorted(map(int, input().split()), reverse=True)
ans, que, cnt = 0, [a[0]], 0
for i in a[1:]:
    ans += que[cnt]
    que += [i, i]
    cnt += 1
print(ans)

-from collections import deque - -ans, cnt = 0, deque([a[0]]) +ans, que, cnt = 0, [a[0]], 0 -    ans += cnt.popleft() -    cnt.extend([i, i]) +    ans += que[cnt] +    que += [i, i] +    cnt += 1