peterverebics/CodeNet_Python_118 huggingface dataset:
N=int(input())
A = sorted(map(int, input().split()),reverse=True)

x=A.pop(0)
cnt=0
conf=0
y=0
for i in A:
  if cnt==0:
    y=i    
  cnt+=1
  if cnt%2==0:
    conf+=p
    x=y
  else:
    p=x+y
    y=i


if cnt%2==1:
  conf+=x
print(conf)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print(sum(a[0:n-1]))
n = int(input())
a = list(map(int, input().split()))

a.sort()
print(a[-1] + a[-2] * (n - 2))
n = int(input())
A = list(map(int, input().split()))

ans = sum(A) - min(A)

print(ans)
n = int(input())
a = list(map(int,input().split()))
b = sorted(a,reverse=True)
print(sum(b)-b[-1])
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
a = a[:-1]
print(sum(a))
# input
N = int(input())
A = list(map(int, input().split()))

# check
sort_A = sorted(A, reverse=True)
print(sum(A[:-1]))
N = int(input())
A = list(map(int,input().split()))

L = []
#ソートして先頭からやる
A.sort(reverse=True)
pprev = A.pop(0)

ans = 0
prev = A.pop(0)
ans = ans + prev


for i in A:
    ans = max(pprev,prev) + ans

    pprev=prev
    prev=i

print(ans)
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in A:
  ans += i
print(ans-1)
n=int(input())
l=sorted(list(map(int,input().split())),reverse=True)
print(sum(l[:-1]))
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort(reverse=True)

ans=a[0]
left=a[1]
right=a[1]

for i in range(2,n):
  if i%2==0:
    ans+=left
    left=a[i]
  else:
    ans+=right
    right=a[i]

print(ans)
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
print(sum(A[:-1]))
from collections import deque

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

A_sorted = sorted(A, reverse=True)
ans = 0
queue = deque([A_sorted[0]])
for a in A[1:]:
    ans += queue.popleft()
    queue.append(a)
    queue.append(a)
print(ans)
N = int(input())
A = [int(_) for _ in input().split()]
print(sum(A) - min(A))
import heapq
from heapq import heappop
n = int(input())
A = list(map(lambda x:-int(x),input().split()))
A.sort()

ans = 0
loop = [A.pop(0)]
heapq.heapify(loop)
heapq.heapify(A)
#二番目に小さい値を加算していく
for i in range(n-1):
    if len(loop)==1:
        a = loop[0]
    else:
        a = loop[1]
    ans+=a
    heapq.heappush(loop,heapq.heappop(A))
    
print(-ans)
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

B = list()
ans = 0
m = 0
n = 3
for i, a in enumerate(A[:3]):
    if i == 0:
        B.append(a)
    elif i == 1:
        ans += B[0]
        B.append(a)
    elif i == 2:
        ans += min(B[0], B[1])
        B.append(a)

j = 1
for i, a in enumerate(A[3:]):
    B.insert(j, a)
    ans += min(B[(j-1)%len(B)], B[(j+1)%len(B)])
    j += 2

print(ans)
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort(reverse=True)
from heapq import heappush, heappop

first = (As.pop(0))
hq = []
if N<2:
    print(0)
else:
    ans = 0
    second = As.pop(0)
    ans += first
    heappush(hq, (-second, -first))
    for a in As:
        s, f = heappop(hq)
        ans -= s
        heappush(hq, (-a, s))
        heappush(hq, (-a, f))

print(ans)
N = int(input())
As = sorted(list(map(int, input().split())), reverse = True)
N -= 1
i = 1
ans = 0
while N > 0:
  if N >= i:
    ans += As[i-1] * i
    N -= i
  else:
    ans += As[i-1] * N
    N = 0
  i += 1
print(ans)
N=int(input())
A=list(map(int, input().split()))
A.sort()
if N==2:
  print(A[1])
  exit()
  
if N==3:
  print(A[2]*2)
  exit()
  
print(sum(A[1:]))
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
total = arr[0]
for i in range(1, n//2):
    total += 2*arr[i]
if n % 2 == 1:
    total += arr[n//2 + 1]
print(total)
n = int(input())
a = list(map(int,input().split()))

print(sum(a)-min(a))
import sys

def main():
    N=int(input())
    A=list(map(int,input().split()))

    A.sort(reverse=True)

    res=0
    for i in range(N-1):
        res+=A[i]
    print(res)

if __name__=="__main__":
    main()
def main():

    N = int(input())
    lst = sorted([int(i) for i in input().split()], reverse=True)
    ans = lst[0]

    n, m = divmod(N - 2, 2)
    ans += sum(lst[1:n + 1]) * 2
    if m:
        ans += lst[n + 2]

    print(ans)


if __name__ == '__main__':
    main()
N = int(input())
A = map(int, input().split())
A = list(A)
print(sum(A) - min(A))
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
order = [a[0]]
ans = 0
for i in range(1,n):
    ans += min(order[-1],order[0])
    order.append(a[i])
print(ans)
N = int(input())
*A, = map(int, input().split())
A.sort(reverse=True)
chk = []
chk.append(A[0])
two = A.count(A[1])
chk.extend([A[1] for _ in range(((two + 1) * 2) - 2)])
if len(A) >= 2:
    for i in range(2, N):
        chk.extend([A[i] for _ in range(2)])
ans = 0
for i in range(N-1):
    ans += chk[i]
print(ans)
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
print(sum(A[:-1]))
all_people = input()
relax = list(map(int, input().split()))

relax_all = 0

relax.sort(reverse=True)

for i in range(int(all_people) - 1):
    relax_all += relax[i]

print (relax_all)
n,ais = int(raw_input()), map(int, raw_input().split())
s = sum(ais)
print s - min(ais)
N=int(input())
aalist=list(map(int,input().split()))
alist=sorted(aalist, reverse=True)
print(sum(alist)-alist[-1])
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)
# print(a)
ans=0
for i in range(1,len(a)):
  ans+=a[i-1]
print(ans)
import sys
input = sys.stdin.readline

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9 6 8 7
# 9+8+7+6+5+6+7+8

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

sm = B[0] + sum(B[i] * 2 for i in range(len(B)) if 0 < i)
print(sm)
n=int(input())
m=[*map(int,input().split())]
print((n-2)*max(m)+min(m))
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
import numpy as np

n = ri()
a = rl()
a=a+a
a.sort()

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

A.sort(reverse = True)

ans = A[0]

idx = 1
cnt = 0
for i in range(2,N):
    ans += A[idx]
    cnt += 1
    if cnt == 2:
        idx += 1
        c = 0

print(ans)
t=int(input())
arr1=list(map(int,input().strip().split()))[:t]
y=min(arr1)
summ=0
for x in arr1:
  summ=summ+x
z=summ-y
print(z)
n = int(input())
a = list(map(int, input().split()))
a.sort()
# print(a)
print(sum(a[2:]) + a[-2])
def main():
    n = int(input())
    A = list(map(int,input().split()))

    A.sort(reverse = True)

    # print(A)

    print(sum(A) - A[-1])


main()
a=int(input())
b=list(map(int,input().split()))
b.sort()
b.remove(b[0])
print(sum(b))
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
A2 = [A[0]] + [a for a in A[1:]]
ans = 0
for a in A2[:n-1]:
    ans += a
print(ans)
N = int(input())
arr = list(map(int, input().split()))
print(sum(sorted(arr)) - sorted(arr)[0])
n=int(input())
a=list(map(int,input().split()))
a.sort()

cnt=0

cnt+=a[-1]
cnt+=a[-2]*(n-2)

print(cnt)
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))

    a_sort = sorted(a, reverse=True)

    ans = a_sort[0]

    if (n-2) % 2 == 0:
        for i in range(int((n-2)/2)):
            ans += a_sort[i+1]*2

    else:
        for i in range((n-2)//2 + 1):
            ans += a_sort[i+1]*2
            temp = i
        ans -= a_sort[temp]

    print(ans)

if __name__ == '__main__':
    main()
import collections

N = int(input())
As = list(map(int, input().split()))

As.sort(reverse = True)

print(As)

circle_que = collections.deque()

circle_que.append(As[0])

ans = 0
for A in As[1:]:
    circle_que.append(A)
    circle_que.append(A)

    ans += circle_que.popleft()
    #print(ans)

print(ans)
n = int(input())
A = list(map(int, input().split()))
if n == 2:
  print(max(A))
else:
  A.sort(reverse=True)
  ans = A[0]
  for a in A[1:n//2]:
    ans += 2 * a
  if n % 2 == 1:
    ans += A[-2]
  print(ans)
n = int(input())-2
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = A[0]
for i in range(n//2):
    ans += 2*A[i+1]
if n%2 != 0:
    ans += A[n//2]
print(ans)
def resolve():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = sum(A[:-1])
    print(ans)

if __name__ == "__main__":
    resolve()
from math import ceil
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
c = 0
for i in range((N+1)//2):
    c += A[i]*2
print(c - A[0] - A[(N+1)//2]*(N&1))
N = int(input())
A = list(map(int, input().split(' ')))

A.sort()
A.reverse()

print(sum(A[0: len(A)-1]))
n=int(input())
a=list(map(int,input().split()))

a.sort(reverse=True)
sum=0
if n==2:
    sum+=a[0]
elif n==3:
    sum+=a[0]+a[1]
elif n>=4:
    sum+=a[0]+a[1]
    #print(sum)
    for i in range(4,n+1):
        sum+=a[i-2]
print(sum)
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

res = 0
for i in range(n - 1):
    res += A[i]
print(res)
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)

ans = A[0] + A[1]*(N-2)
print(ans)
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
result=0
for i in range(2,num+1):
        result+=sample[round(i/2)-1]
print(result)
n = int(input())
a = list(map(int, input().split()))  # 入力のときに N を使う必要はありません

print(sum(a)-min(a))
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans = A[0]
for i in range(2, N):
    ans += min(A[i - 2], A[i - 1])
print(ans)
N = int(input())
A = list(map(int,input().split()))

A = sorted(A, reverse=True)
result = 0

for iter in range(len(A)):
    if iter == 0:
        continue
    if iter == 1:
        result += A[0]
        continue
    result += A[iter-1] if A[iter-1] < A[iter-2] else A[iter-2]


print(result)
N=int(input())
a=input().split()
A=[int(b) for b in a]
AS=sorted(A,reverse=True)
answers=[]
answers.append(AS[0])
del AS[0]
answer=0
for a in AS:
    answer+=answers[-1]
    answers.append(a)
print(answer)
N = int(input())
AN = list(map(int,input().split()))

AN.sort()
print(sum(AN[1:]))
N = int(input())
A = sorted(map(int, input().split()))[::-1]

before = 0
comfort = 0
for i in range(1,N):
    if i == 1:
        comfort += A[0]
    if i == 2:
        comfort += A[1]
        before = A[1]
    if i>2:
        if A[i] == A[i-1]:
            comfort += before
        else:
            comfort += A[i-1]
            before = A[i]

print(comfort)
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()
A.sort(reverse=True)

print(sum(A[:-1]))
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    A.sort(reverse=True)
    ans=sum(A)-A[-1]-A[-2]+A[1]
    print(ans)

main()
n=int(input())
A=[]
A=list(map(int, input().split()))

# print(A)
mina = min( A )
maxa = max( A )

sum = 0
for i in range(n):
    sum +=A[i]

# print(mina)
# print(maxa)
# print(sum)
print(sum-mina)
n = int(input())
al = list(map(int, input().split()))

al = sorted(al)[::-1]
ans = sum(al[:-1])

print(ans)
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
cnt = 0
S = [A[0]]
for i in range(1,N) :
    cnt += min(S)
    S.append(A[i])
print(cnt)
n=int(input())
a_list = list(map(int,input().split()))

a_list = sorted(a_list, reverse=True)

print(sum(a_list[0:-1]))
from collections import deque

d= deque()

N = int(input())
L = map(int,input().split())
L = sorted(list(L))[::-1]
ans = max(L)
prev = max(L)
del L[0]
prev2 = max(L)
del L[0]


for x in L:
    ans += min(prev,prev2)
    prev = prev2
    prev2 = x

print(ans)
a = int(input())
b = list(map(int, input().split(' ')))
b = sorted(b, reverse=True)
b.pop()
point = sum(b)


print(point)
N = int(input())
A_i = list(map(int, input().split()))

forret = sorted(A_i)
ret = A_i[-1]
for i in range(N-1):
    ret = ret + A_i[-1-1-(i//2)]
print(ret)
n = int(input())
values = list(map(int, input().split(' ')))

print(sum(values) - min(values))
import heapq

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = 0
ans += a[0]

h = []
heapq.heapify(h)
heapq.heappush(h, a[1])
heapq.heappush(h, a[1])

for i in range(2, n):
    b = heapq.heappop(h)
    ans += b
    heapq.heappush(h, a[i])
    heapq.heappush(h, a[i])

print(ans)
n=int(input())
l=sorted(list(map(int,input().split())),reverse=1)
ans=0
ri=l[0]
lf=l[0]

ans=0
for i in range(1,n):
    
    ans+=min(ri,lf)
    if i%2:ri=l[i]
    else:lf=l[i]

print(ans)
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(sum(A)-A[0])
import heapq

n=int(input())
a=[-int(x) for x in input().split()]

heapq.heapify(a)
ans=0

while True:
    temp=heapq.heappop(a)
    if len(a)==0:
        break
    ans+=temp

print(-ans)
import bisect
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
anslist = [a[0]]
ans = 0
for i in range(1,n):
    #print(anslist[bisect.bisect_left(anslist, a[i])])
    ans += anslist[bisect.bisect_left(anslist, a[i])]
    bisect.insort(anslist, a[i])
    #print(anslist)
print(ans)
N=input()
A=input().strip().split()
A=[int(s) for s in A]
A.sort()
ans=sum(A[1:])
print(ans)
n = int(input())
a = list(map(int,input().split()))
comf = 0
mincomf = 10**10
for i in range(n):
  comf += a[i]
  mincomf = min(mincomf,a[i])
print(comf-mincomf)
n = int(input())
A = list(map(int, input().split()))
print(sum(A) - min(A))
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    print(sum(arr)-min(arr))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
n = int(input())
an = list(map(int, input().split()))

Ans = sum(an) - min(an)

print(Ans)
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
print(sum(a[:-1]))
def main():
    n=int(input())
    m = 10**9+1
    s = 0
    for a in map(int,input().split()):
        m = min(m, a)
        s += a
    print(s-m)

if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))
print(sum(A)-min(A))
n = int(input())
a_l = list(map(int, input().split()))
a_l = sorted(a_l, reverse=True)

ans = 0
if n == 2:
    ans += a_l[0]
else:
    l = a_l[1]
    r = a_l[2]
    ans += a_l[0] + l
    for i in range(3,n):
        if i%2 != 0:
            ans += l
            l = a_l[i]
        else:
            ans += r
            r = a_l[i]
print(ans)
N=int(input())
A=list(map(int,input().split()))

A.sort(reverse=True)

ans=0

for i in range(N-1):
    ans += A[i+1//2]
print(ans)
import numpy as np

N = int(input())
ARR = list(map(int, input().split()))
ARR = sorted(ARR, key=lambda x: -x)

arr = np.array(ARR)

result = np.sum(arr[:-1])
print(result)
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

for i in range(1,N):
    ans = ans + A[i]*2
print(ans)
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
print(sum(L[0:N-1]))
n=int(input())
As = list(map(int, input().split()))
print(sum(As)-min(As))
if __name__ == "__main__":
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    A.sort(reverse=True)
    print(sum(A[:-1]))
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
ans = 0
ans += a[0]
for i in range(2,n):
  ans += min(a[i-1],a[i-2])
print(ans)
n=int(input())
a=list(map(int,input().split()))
m=1000000001
s=0
for i in range(n):
    s=s+a[i]
    m=min(m,a[i])
print(s-m)
N = int(input())
A = list(map(int,input().split()))
A_new = sorted(A, reverse=True)
A_feel = []
sum = 0
for i in range(N):
  if A_feel == [] or A_new[i] == A_new[0]:
    count = 1
  else:
    count = 2
  for j in range(count):
    A_feel.append(A_new[i])

for i in range(N-1):
  sum += A_feel[i]
  
print(sum)
def main():

    n = int(input())
    a = list(map(int, input().split()))
    list.sort(a,reverse=True)
    ans = a[0]
    
    for i in range(n-3):
        if(i%2 == 0):
            ans += a[i+1]*2
    if (n%2 == 1):
        ans += a[n-3]
    print(ans)
        
if __name__ == "__main__":
    main()
N = int(input())
S = list(map(int,input().split()))

print(sum(S)-min(S))
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
C = A[0]+A[1]
for i in range(3,N):
  C = C+max(A[i-1],A[i-2])
print(C)
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

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

score = a[0]
score += a[1]

for i in range(2,n):
    score += min(a[i-1],a[i-2])

print(score)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = 0
for i in range(n):
    if i==0:
        ans += 0
    elif i == 1:
        ans += a[0]
    else:
        ans += a[i//2 + 1]
print(ans)
from collections import deque
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
ans=0
x=deque([a[0]])
for i in range(1,n):
  ans+=min(x[0],x[-1])
  x.append(a[i])
  x.appendleft(a[i])
print(ans)
import math
import collections

n = int(input())
li = list(map(int, input().split(" ")))

li = sorted(li, reverse=True)

ans = 0
d = collections.deque([])
for i, l in enumerate(li):
    if i == 0:
        d.append(l)
        continue
    if d[0] > d[-1]:
        bef = d[0]
        d.appendleft(l)
        aft = d[-1]
        ans += min(bef, aft)
    else:
        bef = d[-1]
        d.append(l)
        aft = d[0]
        ans += min(bef, aft)

print(ans)
n = int(input())
a_l = list(map(int, input().split()))
a_l = sorted(a_l, reverse=True)

ans = 0
c = a_l[0]
for i in range(n-1):
    c = a_l[i]
    ans += c
print(ans)
import sys
import numpy as np
from math import ceil
from collections import defaultdict as D

def S(): return sys.stdin.readline().rstrip().split(' ')
def Ss(): return list(S())
def I(): return _I(Ss())
def Is(): return list(I())
def _I(ss): return map(int, ss) if len(ss) > 1 else int(ss[0])

_ = S()
xs = Is()

xs = sorted(xs, reverse=True)
print(np.sum(xs[:-1]))
from sys import stdin
N = int(input())
A = [int(x) for x in stdin.readline().rstrip().split()]
A.sort(reverse=True)
ans = A[0]
cnt = 2
for i in range(1,N):
    ans += (A[i]*2)
    cnt += 2
    if cnt >= N:
        if cnt > N:
            ans -= A[i]
        break
if N == 2:
    ans = min(A)
print(ans)
N = int(input())
n = 0
A = list(map(int,input().split()))
cnt = int(0)
A.sort(reverse=True)
ans = 0
if N < 5:
  for num in range(N-1):
    ans += A[num]
else:
    while cnt<N-1:
      ans += A[n]
      cnt += 1
      n += 1
      if cnt >= N:
        break
      ans += A[n]
      cnt+=1
print(ans)
n=int(input())

a = input().split()

a.sort()
int_a= [int(s) for s in a]
sum=sum(int_a)

print(sum-int_a[0])
n = int(input())
a = list(map(int,input().split()))
a1 = sorted(a)
ans = 0
for i in range(n-1):
  ans += a[n-1-(i//2)]
print(ans)
n = int(input())
A = list(map(int,input().split()))

m = min(A)
print(sum(A)-m)
N=int(input())
A=list(map(int, input().split()))
A=sorted(A,reverse=True)

cnt=0
for i in range(1,N):
  cnt+=A[i-1]
print(cnt)
N = int(input())

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

if len(players) == 1:
    total = 0
else:
    players.sort(reverse=True)
    total = players[0] + players[1] * (len(players) - 2)

print(total)
n = int(input())
a = list(map(int,input().split()))
a.sort()
c = int(a[-1])
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = int(a[n-2-i])
    c += a1*2
else:
  c += int(a[n - 2])
  n2 = n//2 - 1
  for i in range(n2):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)
N=int(input())
A=input().split()
for i in range(N): A[i]=int(A[i])
A.sort()
#print(A)
r=0
for i in range(N):
  if i>0: r+=A[i]
print(r)
n = int(input())
sum(sorted([int(x) for x in input().split()] * 2, reverse = True)[1:n])
N = int(input())
players = list(map(int, input().strip().split(" ")))

players.sort(reverse=True)
total = 0
for i in range(N-1):
    j = int((i+1)/2)
    total += players[i]
print(total)
N=int(input())

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

li.sort()
if N%2==0:
  print(sum(li[int(-N/2)-1:-1])+li[-1])
else:
  print(sum(li[-(N//2)-1:-1])+li[-1]+li[-(N//2)-1])
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

ans = A[0] + A[1]*(n-2)
print(ans)
n = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
confort = 0
for a in A[:n-1]:
    confort = confort + a

print(confort)
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = 0
for i in range(0, len(A) - 1):
  ans += A[i]
print(ans)
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
C = 0
for i in range(1,N):
  C = C+A[i-1]
print(C)
n = int(input())
a = list(map(int,input().split()))
a.sort()
med = a[n//2]
b = [a[i]-med for i in range(n)]
b.sort()
print(sum(b[1:])+med*(n-1))
def judge():
    ans = True
    return ans

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

sum = 0
val = False
d_max = 1
d_max2 = 1
for d in a:
    sum += d
    if d > d_max:
        d_max2 = d_max
        d_max = d
    if d > d_max2 and d_max > d:
        d_max2 = d
print (d_max + (n-2)*d_max2)

# 2番めに大きいやつは確実に選べるのでは？
N=int(input())
ls=[int(s) for s in input().split()]
ls=sorted(ls,reverse=True)
ans=ls[0]
if N>=3:
  ans+=ls[1]
for i in range(3,N):
  ans+=ls[i-2]
print(ans)
import itertools
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
C = list(itertools.accumulate(A))

print(C[-2])
n=int(input())
a=[*map(int,input().split())]
a.sort(reverse=True)
sum=0
for i in range(n-1):
  sum+=a[i]
print(sum)
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

ans = A[0]
left = A[1]
right = A[1]
for i in range(2, len(A)):
    if i % 2 == 0:
        ans += left
        left = A[i]
    else:
        ans += right
        right = A[i]

print(ans)
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort(reverse=True)
i=0
j=0
res=0
n-=1
while n:
    k=min(2**i,n)
    res+=(k)*arr[j]
    #print(res)
    n-=k
    j+=1
    i+=1
print(res)
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    nums = [int(x) for x in input().split()]
    nums.sort(reverse=True)

    r = [nums.pop(0)]

    ans = 0
    while len(nums):
        n = nums.pop(0)
        i = r.index(max(r))
        ans += r[i]
        r = r[0:i] + [n] + [n] + r[i+1:-1]

    print(ans)


if __name__ == '__main__':
    main()
n = int(input())
li_a = list(map(int,input().split()))
li_a.sort(reverse=True)

ans = 0
for i in range(n-1):
    ans += li_a[i]

print(ans)
N = int(input())
A_i = list(map(int, input().split()))

ret = sum(A_i)-min(A_i)
print(ret)
n = int(input())
a = sorted(list(map(int, input().split())), reverse = True)

ans = 0

for i in range(1, n):
    ans += a[i-1]

print(ans)