peterverebics/CodeNet_Python_118 huggingface dataset:
import numpy as np
N = int(input())

A = np.array([int(i) for i in input().split()])
A_sort = np.sort(A)

#print(A_sort)
score = 0
score += A_sort[-1]
for i in range(0, (N-2)//2):
    score += A_sort[-2-i] * 2
    
if (N-2) % 2 == 1:
    score += A_sort[-3-i]
    
print(score)
N = int(input())
A = sorted(map(int, input().split()), reverse=True)

answer = 0
consume = N
for a in A:
    if consume == N:
        consume -= 2
        if N > 1:
            answer += a
        continue
    elif consume > 1:
        answer += a * 2
        consume -= 2
        continue
    elif consume == 1:
        answer += a
        consume -= 1
        continue
    else:
        break

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

a.sort(reverse=True)
n -= 2
r = a[0]
i = 1
while n-2 >= 0:
    r += a[i]*2
    i += 1
    n -= 2
if n==1:
    r += a[i]
print(r)
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i in range(n - 1):
  ans += a[(i + 1) // 2]
print(ans)
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
cnt = A[0]
k = (N+1)//2-1
for i in range(1,1+k):
    cnt += 2*A[i]
if N%2==1:
    cnt -= A[k]
print(cnt)
#D
N = int(input())
A = list(map(int,input().split()))

A.sort()

sc = 0
sc += A.pop(-1)

c=0
for i in range(10**6):
    if c>=N-2:
        break
    p=A.pop(-1)
    sc+=p
    c+=1
    if c>=N-2:
        break
    sc+=p
    c+=1
        
print(sc)
n = int(input())
a = list(map(int,input().split()))

a.sort(reverse = True)

ans = 0

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

print(ans)
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort(reverse = True)
res = 0
ind = 0
for i in range(1,n):
    res += a[ind]
    if i%2:
        ind += 1
print(res)
N=int(input())
A=list(map(int,input().split()))
A.sort()
A.insert(0,0)

ans=0
for i in range(1,N):
    ans+=A[N-int(i/2)]

print(ans)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
count = 0
cou = 1
while cou<n:
    cou*=2
    count += 1
sum = 0
for i in range(n-1):
    j = (i+1) // 2
    sum += a[j]

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

ans=a[0]
c=1
i=1
while c<n-1:
    ans+=a[i]
    c+=1
    if c>=n-1:
        break
    else:
        ans+=a[i]
        c+=1
    i+=1
print(ans)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = a[0]
cnt = 1
for i in range(1, n):
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
print(ans)
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n=r()
a=rl()
a.sort(reverse=True)
b=[0,a[0]]
i=1
while len(b)<n and i<n:
    b.append(a[i])
    b.append(a[i])
    i+=1
print(sum(b[:n]))
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

res = a[0]
cnt = 0
i = 1
for _ in range(n-2):
    res += a[i]
    cnt += 1
    if cnt == 2:
        i += 1
        cnt = 0
print(res)
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
A = sorted(A,reverse=True)
if N % 2 == 0: 
    k = N // 2
    ans = sum(A[:k])*2-A[0]
else:
    k = N // 2 + 1
    ans = sum(A[:k])*2-A[0]-A[k-1]
print(ans)
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
if n % 2:
    print(a[0]+a[n//2]+2*(sum(a[1:(n-1)//2])))
else:
    print(a[0]+2*(sum(a[1:n//2])))
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)

if N%2==0:
    ans = sum(A[:N//2]) * 2 - A[0]
else:
    ans = sum(A[:N//2]) * 2 - A[0] + A[N//2]
print(ans)
import heapq

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

q = []
heapq.heappush(q, -data[1])
heapq.heappush(q, -data[1])
result = data[0]

for i in range(2, n):
    result += -heapq.heappop(q)
    heapq.heappush(q, -data[i])
    heapq.heappush(q, -data[i])

print(result)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
for i in range(n-2):
    ans += a[i//2+1]
print(ans)
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
if len(a)==1:
  print(0)
else:
  s=a[0]
  for i in range(len(a)-2):
    s+=a[i//2+1]
  print(s)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = a[0]
cnt = 0
j = 1
for i in range(2, n):
    if cnt < 2:
        ans += a[i-j-cnt]
        cnt += 1
    if cnt == 2:
        cnt = 0
        j += 1
print(ans)
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    sorted_A = sorted(A, reverse=True)
    cnt = N
    ptr = 0
    is_first = True
    ans = 0
    while cnt > 0:
        ans += sorted_A[ptr]
        if is_first:
            is_first = False
        else:
            ptr +=1
            is_first = True
        cnt -= 1
    print(ans - sorted_A[0])

if __name__ == "__main__":
    solve()
import math
n=int(input())
a=input()
al=[int(i) for i in a.split()]
al.sort(reverse=True)
ans=al[0]
for i in range(math.floor((n-2)/2)):
    ans+=al[i+1]*2
if round((n-2)/2)-(n-2)/2!=0:
    ans+=al[math.floor((n-2)/2)+1]
print(ans)
n = int(input())
lst = list(map(int,input().split()))

lst.sort(reverse=True)
if n % 2 == 0:
  a = n//2-1
  s = lst[0]
  for i in range(a):
    s += 2*(lst[i+1])
  
else:
  b = (n-1) //2
  s = lst[0]
  for j in range(b):
    s += 2*(lst[j+1])
  s -= lst[b]
  
print(s)
from collections import deque
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
A.sort(reverse = True)
ans = 0
que = deque()
que.append(A[0])
for i in range(1,len(A)):
    ans += que[0]
    que.popleft()
    que.append(A[i])
    que.append(A[i])
print(ans)
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)
ans = A[0]+A[1]

for i in range(2,N-1):
  ans += max(A[i],A[i-1])
print(max(ans,sum(A[:-1])))
# -*- coding: utf-8 -*-

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

A = sorted(A)[::-1]

ans = 0
for i, a in enumerate(A):
    if i==0:
        ans += a
        itr = 2
    else:
        ans += a
        itr += 1
        if itr >= N:
            break
        ans += a
        itr += 1
        if itr >= N:
            break

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()))
# print(N)
# print(A)
A.sort(reverse=True)
ans = sum(A[0:N - 1])
print(ans)
from heapq import heapify, heappop, heappush
N,*A=map(int, open(0).read().split())
A=sorted(A, reverse=True)
L=[0]*N
R=[0]*N
ans=0
L[0]=0
R[0]=0
H=[(A[0],0,0)]
heapify(H)
for i in range(1,N):
    a=A[i]
    p,pl,pr=heappop(H)
    ans+=p
    L[pr]=i
    R[pl]=i
    L[i]=pl
    R[i]=pr
    heappush(H,(min(A[pl],a),pl,i))
    heappush(H,(min(A[pr],a),i,pr))
print(ans)
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)

ans = sum(A[:N // 2]) * 2 - A[0]

print(ans)
if N % 2 == 1:
    ans += A[N // 2]

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

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

out = sum(nums) - min(nums)
print(out)
import copy
 
inp = input()
friends = input()
friendList = friends.split()
sortedFriends = sorted(friendList, reverse=True)
confs = [sortedFriends[0]]
# copied = copy.deepcopy(sortedFriends)[1:]
sortedFriends.extend(sortedFriends[1:])

sortedFriends = sorted(sortedFriends, reverse=True)
 
#for i in sortedFriends:
    # print(int(i))
confSum = 0
for i in range(int(inp)-1):
    conf = int(sortedFriends[i])
    confSum += conf
print(str(confSum))
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
ans = 0
min_a = a[0]

for i in range(len(a)-1):
    ans += min_a
    if min_a > a[i+1]:
        min_a = a[i+1]

print(ans)
import sys
input =sys.stdin.readline

N=int(input().rstrip('\n'))
As=[int(x) for x in input().rstrip('\n').split()]
As_s=sorted(As)
print(sum(As_s[1:]))
n = int(input())
a =[int(i) for i in input().split()]
a.sort(reverse=True)

s = sum(a)-a[-1]
print(s)
n = int(input())
a_list = list(map(int,input().split()))

print(sum(a_list)-1)
from collections import defaultdict as dd
import heapq
N = int(input())
a = list(map(int,input().split()))
res = 0
a = sorted(a, reverse=True)
dic=dd(list)
ls = [a[0]]
heapq.heapify(ls)
for val in a[1:]:
    tmp = heapq.heappop(ls)
    res += tmp
    heapq.heappush(ls,val)
    heapq.heappush(ls,val)
print(res)
n=int(input())
l=list(map(int,input().split()))
print(sum(l)-min(l))
import queue

def main():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A,reverse=True)
    q = queue.PriorityQueue()
    q.put([A[0],A[0]])
    ans = 0
    for a in A[1:]:
        _min, _max = q.get()
        ans += _min
        q.put([a,_min])
        q.put([a,_max])
    print(ans)
    return 

if __name__ == "__main__":
    main()
N = int(input())
a = list(map(int,input().split()))
# print(N,a)

a_sort = sorted(a, reverse=True)

a_sum = a_sort[0]

if N-2 % 2 == 0:
    for i in range((N-2)/2):
        a_sum += 2*a_sort[i+1]
else:
    for i in range((N-2)//2):
        a_sum += 2*a_sort[i+1]
print(a_sum)
n = int(input())
lst = [int(i) for i in input().split()]

list.sort(lst)
lst2 = []
total = 0
for i in range(n):
  num = lst[i]
  if not lst2:
    lst2.append(num)
  if len(lst2) == 1:
    total += lst2[0]
    lst2.append(num)
  if len(lst2) == 2:
    total += lst2[1]
    lst2.pop(1)
    lst2.append(num)
print(total)
import sys


def resolve(in_):
    n = int(in_.readline())
    a = list(map(int, in_.readline().split()))
    assert len(a) == n
    a.sort(reverse=True)
    return sum(a[:-1])


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
import numpy as np

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

print(A[1:].sum())
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)[::-1]
    if n %2== 0:
        print(a[0]+sum(a[1:n//2]))
    else:
        print(a[0]+sum(a[1:n//2+1])*2)



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

A.sort()
A.pop(0)

print(sum(A))
n=int(input())
a=list(map(int,input().split()))
print(sum(a)-min(a))
n = int(input())
l = list(map(int, input().split()))
Sum = sum(l)

print(Sum-min(l))
N=int(input())
AA=list(map(int,input().split()))
AA=sorted(AA)[::-1]
print(sum(AA)-AA[-1])
N = int(input())
A = list(map(int, input().split()))

A.sort()
A.reverse()

happy =  0
circle = [A[0], A[1]]
for i in range(2, N):
    circle.insert(len(circle)-2, A[i])
    happy += min(circle[-1], circle[-3])

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

A.sort()
A.reverse()

list = []
ans = 0
list.append(A[0])
for i in range(len(A)):
        ans += list[i]
        list.append(A[i])
        list.append(A[i])

print(ans)
N = int(input())
ln = list(map(int, input().split()))
total = 0
ln = sorted(ln, reverse = True)
print(sum(ln[:-1]))
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n=II()
	A=LI()
	A.sort(reverse=True)

	ans=A[0]
	ans+=2*sum(A[1:(n+1)//2-1])

	if n%2:
		ans+=A[n//2]

	print(ans)











if __name__ == "__main__":
	main()
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
result = 0
for i in range(N):
    result += A[(i + 1) // 2]
print(result)
# 整数の入力
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))
A = np.array(A_list)
ans = np.sum(A) - np.max(A)
print(ans)
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(1, n):
    ans += a[i]
print(ans)
import math

n=int(input())
seq=list(map(int,input().split()))
print(sum(seq)-1)
#from itertools import combinations 
import sys
import math as mt
input=sys.stdin.buffer.readline  
t=1


#t=int(input())
for _ in range(t):
    n=int(input())
      
    #n,m,k=map(int,input().split())
    l=list(map(int,input().split()))
    suma=sum(l[:])
    mini=min(l[:])
    print(suma-mini)
l = int(input())
 
a = map(int, input().split())
a = sorted(a, reverse=True)
#print(a)
if l%2==0:
	print(a[0] + sum(a[1:(l-2)//2])*2 + a[(l-2)//2])
else:
	print(a[0] + sum(a[1:(l+1)//2])*2)
from collections import deque

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

confort = 0

edge = []

for i in range(n):
    if i == 0:
        continue
    elif i == 1:
        confort += friendly[0]
        edge.append(friendly[1])
        edge.append(friendly[1])
    else:
        max_edge = friendly[i-1]
        confort += max_edge
        edge.insert(edge.index(max_edge), friendly[i])
        edge.insert(edge.index(max_edge) + 1, friendly[i])
        
print(confort)
import itertools
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
ans = 0
for L in itertools.permutations(A):
    temp = 0
    for i in range(N-1):
        temp += min(L[i-1], L[i+1])
    ans = max(ans, temp)
print(ans)
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)
    ans = sum(A) - min(A)

    if (A[0] > 1 and A[0] == A[1]):
        ans += A[0] - A[-2]

    print(ans)

resolve()
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = solve(n, a)
    print(ans)

def solve(n, a):
    a.sort()
    ans = 0
    ans += sum(a[-(n // 2) - n % 2:])
    ans *= 2
    if n % 2:
        ans -= a[-(n // 2)]
    ans -= a[-1]
    return ans

if __name__ == '__main__':
    main()
N = int(input())
A = sorted(map(int, input().split()))

print(sum(A[1:]))
n = int(input())
lis = list(map(int, input().split()))

lis = sorted(lis, reverse=True)

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

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

print(ans)
n=int(input())
lst=[]
person=list(map(int,input().split()))
person.sort(reverse=True)
conv=0
for i in range(n):
  lst.append(person[i])
  if len(lst)>=2:
    conv+=min(lst[0], lst[len(lst)-2])
print(conv)
N = int(input())
A = list(map(int,input().strip().split()))
A = sorted(A)

if N == 1:
    print(0)
else:
    print(sum(A[1:]))
N=int(input())
input1=list(map(int,input().split()))
max1=0
for  i in input1:
	if sum(input1)-i >=max1:
		max1=i 
print(max1)
input()
print(sum(sorted(list(map(int, input().split())))[1:]))
n=int(input())
arr=sorted(list(map(int,input().split())))

t=sum(arr)
print(t-arr[0])
n = int(input())
As = [int(x) for x in input().split()]
print(sum(As) - min(As))
import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = sum(a[:2])
    que = [(a[-2], a[-1])]
    heapq.heapify(que)
    for i in range(2, n):
        x, y = heapq.heappop(que)
        ans += min(x, y)
        heapq.heappush(que, (a[i], x))
        heapq.heappush(que, (a[i], y))
    return ans

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)

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

ans = A[0]

for i in range(2,N):
  I = (i+2)//2
  ans += A[I]
  
print(ans)
n = int(input())

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

score_list = [0]
for i in range(1, len(A)):
    score_list.append(A[i])
    score_list.append(A[i])
    
print(sum(score_list[:n-1]))
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

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

a.sort(reverse=True)

migi = a[1]
hidari = a[1]
point = a[0]

for i in a[2:]:
    if migi >= hidari:
        point += migi
        migi = i
    else:
        point += hidari
        hidari = i

print(point)
N = int(input())
AA= list(map(int,input().split()))
AA.sort(reverse=True)
ccurrent = AA.pop(0)
conf = 0
for a in AA:
  conf+=ccurrent
  ccurrent = a
print(conf)
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
print(sum(A[:n-1]))
from collections import deque

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

A.sort(reverse=True)
A = deque(A)
res = 0
C = A.popleft()

for n in range(N-1):
    res += C
    C = A.popleft()
print(res)
N = int(input())
A = list(map(int, input().split()))
A_rev = sorted(A, reverse=True)
print(sum(A_rev[:-1]))
n = int(input())
a_list = list(map(int, input().split()))

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

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))

a.sort()
a.pop(0)
print(sum(a))
n = int(input())
a = list(map(int,input().split()))

a.sort()
print(sum(a[1:]))
import math

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

A.sort(reverse=True)

comfortPoint = A[0]

for i in range(N)[1::]:
    comfortPoint += A[math.ceil(i/2)]

print(comfortPoint)
N=int(input())
lis=list(map(int,input().split()))
lis.sort()
print(sum(lis[::-1][:-1]))
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    
    Taku = []

    A.sort()
    A.reverse()
    flg = 0

    ans = 0

    for an in A:
        if flg == 0:
            Taku.append(an)
            flg = 1
        else:
            Takudiff = [min(Taku[i], Taku[i-1]) for i in range(len(Taku))]
            Taku.insert(Taku.index(max(Takudiff)), an)
            ans += max(Takudiff)

    print(ans)

solve()
N = int(input())
*A, = map(int, input().split())
A = sorted(A, reverse=True)
ans = sum(A[:-1])
print(ans)
# -*- coding: utf-8 -*-
n = int(input())
b = list(map(int,input().split()))

b.sort(reverse=True)
ret = 0
from collections import deque
stack_deque = deque([])
if n == 1:
    print(0)
    import sys
    sys.exit()
if n == 2:
    print(b[1])
    import sys
    sys.exit()

stack_deque.append(b[1])
stack_deque.append(b[1])
ret = b[0]
for bi in b[2::]:
    ret += stack_deque.popleft()
    stack_deque.append(bi)
    stack_deque.append(bi)
print(ret)
N=int(input())
A=list(map(int,input().split()))

A.sort()
ans=A[-1]+(N-2)*A[-2]
print(ans)
n = int(input())

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

L = sorted(L,reverse=True)
#print(L)

cnf = 0
for i in range(1,n):
    cnf += L[i-1]
    #print(i,cnf)

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

A.sort()
A.reverse()

happy = A[0]
circle = [A[0], A[1]]
for i in range(2, N):
    circle.insert(len(circle)-1, A[i])
    happy += min(circle[-1], circle[-3])

print(happy)
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
i=len(A)
i//=2
print(sum(A[-i-2:-2])*2+A[-1])
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
P=A[0]
for i in range(2,N):
  P+=min(A[i-1],A[i-2])
print(P)
n = int(input())
a = list(map(int, input().split()))
a=sorted(a,reverse=True)
ans=0
for i in range(n-1):
    if i<n//2+1:
        ans+=a[i]
    else:
        ans+=a[i-n//2]

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

a.sort(reverse=True)

score = a[0]

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()
print(sum(A[1:]))
n = int(input())
A = input()
A = A.split()
A = [int(i) for i in A]
A = sorted(A, reverse = True)
ans = 0

for x in A:
	ans += x

ans -= A[n-1]

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

a.sort(reverse=True)

cnt = 1
ans = a[0]

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

print(ans)
n = int(input())
a = 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:
  n2 = n//2
  a3 = int(a[n-n2])
  c += a3
  for i in range(n2-1):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)
num=input()
s=[int(i) for i in input().split()]
s.sort(reverse=True)
point=0
for (i,j) in enumerate(s):
    if i+1==len(s):
        break
    point+=j
print(point)
def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    print(sum(friendliness) - 1)


if __name__ == '__main__':
    main()
n=int(input())
x=[int(x) for x in input().split()]
x.sort(reverse=True)
f=1
ans=x[0]
ans+=(n-2)*x[1]
print(ans)
N=int(input())
A=list(map(int,input().split()))
A.sort()
A.reverse()
count=0
for i in range(N-1):
    count+=A[i]
print(count)
n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
a = sorted(a, reverse=True)

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

print(sum)
n = int(input())
alist = list(map(int,input().split()))

alist = sorted(alist,reverse=True)

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

print(ans)
N=int(input())
A=list(map(int,input().split()))
A.remove(min(A))
print(sum(A))
N = input()
S = list(map(int,input().split()))
 
max=S[0];
 
semimax=S[1];
 
val=max;
 
for i in range(int(N)-2):
	val+=semimax
	if S[i+1]>max:
		max=S[i+1]
		if S[i+1]>semimax:
			semimax=S[i+1]

print(val)
import math
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
for i in range(N - 1):
    ans += A[N - math.ceil(i / 2) - 1]
    print(ans)
print(ans)
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ANS = A[0]

for i in range(N-2):
    index = i // 2
    print(index)
    ANS += A[index+1]
print(ANS)
N=int(input())
N-=1
a=list(map(int,input().split()))
a.sort
a.reverse()
b=0
c=0
if N % 2==1:
  b+=a[0]
  c+=1
  i=0
  while True:
    if c==N:
      print(b)
      break
    else:
      i+=1
      c+=2
      b+=2*a[i]
  
if N % 2==0:
  b+=a[0]
  c+=1
  i=0
  while True:
    i+=1
    c+=2
    b+=2*a[i]
    m=N-c
    if m==1:
      b+=a[i]
      print(b)
      break
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
flag = True
check = min(a)
ans = 0
for i in a:
    if flag and i == check:
        flag = False
    else:
        ans += i
print(ans)
import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = sum(a[:1])
    que = [(-a[1], -a[0])]
    heapq.heapify(que)
    for i in range(2, n):
        x, y = heapq.heappop(que)
        ans += min(-x, -y)
        heapq.heappush(que, (-a[i], x))
        heapq.heappush(que, (-a[i], y))
    return ans

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
N = int(raw_input())
A = (map(int, raw_input().split()))
A.sort(reverse=True)
ans = 0
for i, x in enumerate(A):
  if i:
    ans += A[i-1]
print ans
N = int(input())
A = list(map(int, input().split()))

A.sort()

print(sum(A[1:]))