peterverebics/CodeNet_Python_118 huggingface dataset:
N = int(input())
A = sorted(map(int, input().split()))[::-1]


circle = A[:3]
ans = circle[0]
ans += circle[1]


A = A[3:]

for a in A:
  min_idx = -1
  max_val = 0
  for i, ab in enumerate(zip(circle, circle[1:]), start=1):
    tmp = min(ab)
    if tmp > max_val:
      max_val = tmp
      min_idx = i
  tmp = min([circle[0], circle[-1]])
  if tmp < max_val:
    max_val = tmp
    min_idx = 0
  ans += max_val
  circle.insert(min_idx, a)

print(ans)
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
print(sum(a)-a[n-1])
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()))
B=sorted(A,reverse=True)
print(B)
s=B[0]
for i in range(1,N-1):
    s+=B[i]
print(s)
n = int(input())
a = sorted(list(map(int, input().split())))
print(sum(a[1:]))
n = int(input())
a = sorted(map(int, input().split()))

print(sum(a[1:]))
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)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print (sum(a[:-1]))
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]
    print(a_sum)
else:
    for i in range((N-2)//2):
        a_sum += 2*a_sort[i+1]
    print(a_sum+a_sort[(N-2)//2 + 1])
N=int(input())
comfort=list(map(int,input().split()))
comfort.sort(reverse=True)
print(sum(comfort[:-1]))
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
if n%2==0:
    s=0
    s=2*(sum(a[0:(n//2)]))-a[0]
    print(s)
else:
    s=0
    s=2*(sum(a[0:(n//2)+1]))-a[0]-a[(n+1)//2]
    print(s)
n = int(input())
a = list(map(int, input().split()))

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

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

a.sort(reverse=True)

point = 0
num = a[0]
for i in range(1, n):
  if num >= a[i]:
    point += num
    num = a[i]

print(point)
N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
ans=0
for i in range((N//2)+1):
  for j in range(2):
    ans+=A[i]
if (N//2)%2==1:
  ans-=A[i]
if N//2!=0:
  ans-=A[0]

print(max(ans,0))
n=int(input())
alist=list(map(int,input().split()))

alist.sort()
print(sum(alist)-alist[0])
# @author 

import sys

class DChatInACircle:
    def solve(self, tc=0):
        n = int(input())
        a = [int(_) for _ in input().split()]
        a.sort()
        it = [a[-1], a[-2], a[-2]] + list(reversed(a[:-2]))
        print(sum(it[:n - 1]))


solver = DChatInACircle()
input = sys.stdin.readline

solver.solve()
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
del a[-1]
print(sum(a))
N = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = 0
for i in range(N - 1):
    ans += arr[i]
print(ans)
n = input()
xs = [ int(x) for x in input().split() ]
xs.sort(reverse=True)
best, buf = 0, [xs[0]]
for x in xs[1:]:
  i, y = max([ (min(buf[i-1], y), i) for i,y in enumerate(buf) ])
  best += y
  buf.insert(i, x)
print(best)
N = int(input())

A = [int(x) for x in input().split()]

print(sum(A) - min(A))
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(sum(a)-a[-1])
n = int(input())
lst = [int(i) for i in input().split()]
 
list.sort(lst, reverse=True)
#print(lst)
lst2 = []
total = 0
for i in range(n):
  num = lst[i]
  if len(lst2) == 2:
    total += lst2[1]
    lst2.pop(1)
    lst2.append(num)
  if len(lst2) == 1:
    total += lst2[0]
    lst2.append(num)
  if not lst2:
    lst2.append(num)
  #print(total)
print(total)
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N = int(input())
A = [int(_) for _ in input().split()]
A = sorted(A, reverse=True)

print(sum(A[:-1]))
n = int(input())
que = [x*-1 for x in list(map(int,input().split()))]

import heapq
from collections import deque
heapq.heapify(que)
ans = heapq.heappop(que)*-1
que = deque(que)
que.pop()
while que:
  m = que.popleft()
  ans += m*-1
  if len(que)>0:
    que.pop()
    ans += m*-1
  

print(ans)
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(sum(a)-a[0])
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
for num in range(len(A)-1):
  ans += A[num]
print(ans)
n = int(input())
a = list(map(int, input().split()))
a = list(reversed(sorted(a)))

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

print(result)
n = int(input())
l = list(map(int,input().split()))
a = min(l)
b = 0
for i in range(n):
  b = b + l[i]
print(b-a)
N=int(input())
input1=list(map(int,input().split()))
max1=0
for  i in input1:
	if sum(input1)-i >max1:
		max1=i 
print(max1)
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
temp = a[0]
lim = 1
cnt = 1
for v in a[1:]:
  if lim==0:
    temp = pre
    lim = cnt
    cnt += 1
  ans += temp
  cnt += 1
  lim -= 1
  pre = v
print(ans)
n = int(input())
arr = [int(x) for x in input().split()]

print(sum(arr) - min(arr))
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=1)
    players = [A[0], A[0]]
    ans = 0
    for a in A[1:]:
        if players[1] > players[-2]:
            ans += players[1]
            players = [players[0]] + [a] + players[1:]
        else:
            ans += players[-2]
            players = players[:-1] + [a] + [players[-1]]
    print(ans)


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

a.sort()
suma = sum(a)-a[0]

print(suma)
n = int(input())
a = list(map(int,input().split()))
med = a[n//2]
b = [a[i]-med for i in range(n)]
b.sort()
print(sum(b[1:])+med*(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()))
s = sorted(a, reverse=True)
print(sum(s[:-1]))
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)

print(sum(a[:-1]))
n = int(input())
a = sorted(list(map(int,input().split())))
su = sum(a)-a[-1]
print(su)
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = 0
for i in range(n - 1):
    b += a[i]
print(b)
import sys
input = sys.stdin.readline

N = int(input())
A = [int(_) for _ in input().split()]

sa = sorted(A)

print(sum(sa) - sa[0])
n = int(input())
lis = list(map(int,input().split()))
print(sum(lis)-min(lis))
N = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
s = l[0]
if N%2==0:
  c = N//2-1
  for i in range(c):
    s = s + l[i+1]*2
  
else:
  d = (N-3)//2
  for i in range(d):
    s = s + l[i+1]*2
    s = s+l[(N-1)//2]
print(s)
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

ans = 0
for i in range(N):
    if i == 0:
        m = A[i]
    else:
        ans += m
        m = A[i]
print(ans)
import heapq
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    a = sorted(a)
    ans = 0

    paired = []

    prev = a.pop()
    temp = a.pop()
    heapq.heappush(paired,(-temp,-prev))
    ans += prev

    
    for _ in range(n-2):
        temp = a.pop()
        pair = heapq.heappop(paired)

        ans -= pair[0]
        heapq.heappush(paired,(-temp,pair[0]))
        heapq.heappush(paired,(-temp,pair[1]))

    print(ans)

if __name__ == "__main__":
    main()
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
P=A[0]
if N==2:
  print(P)
  exit()
P+=A[1]
for i in range(3,N):
  P+=A[((i>>1)<<1)-1]
print(P)
from sys import stdin
from sys import setrecursionlimit

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
a.sort(reverse=True)

point = a[0]

one = a[0]
two = a[1]

for i in a[2:]:
    point += two
    one = two
    two = i

print(point)
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
a = LI()
a.sort(reverse=True)
ans = sum(a[:2])
if n<=3:
	print(ans)
else:
	ans = sum(a[:3])
	for i in range(3,n-1):
		if i%2 == 1:
			ans+=a[i-2]
		else:
			ans+=a[i-1]
	print(ans)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print(sum(a[:n-1]))
n = int(input())
comforts = list(map(int,input().split()))
newcomforts = sorted(comforts, reverse=True)
print(newcomforts[1] * (n-2) + newcomforts[0])
import math
n = int(input())
a = list(map(int,input().split()))
b = sorted(a,reverse=True)
x = math.ceil(len(b)/2)
y = b[:x]
z = sum(y*2)-y[0]
if x%2==1:
    print(z-y[-1])
else:
    print(z)
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
# print(f'{A=}')
ans = sum(A) - A[-1]
print(ans)
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=sum(a)
ans-=a[0]
print(ans)
N = int(input())
S = input().split()
A = []
for s in S:
    A.append(int(s))
A.sort(reverse=True)

result = 0
for i in range(N-1):
    result += A[i]
print(result)
N = int(input())
nums = [int(i) for i in input().split()]


nums = sorted(nums, reverse=True)


a_sum = 0
for i in range(N-1):
    if i == 0:
        index = 0
    else:
        index = (i-1)//2 + 1
    print(index)
    a_sum += nums[index]

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

a.sort(reverse=True)

if n == 1:
    ans = 0
elif n == 2:
    ans = a[0]
elif n == 3:
    ans = a[0] + a[1] * 2
elif n > 3:
    ans = a[0] + a[1] * 2 + sum(a[3:-1])

print(ans)
n=int(input())
a=list(map(int, input().split()))
go=0
for x in a:
    go+=x
print(go-min(a))
#D
N=int(input())
A=sorted(list(map(int,input().split())))[::-1]
ans=0
#print(A)

from collections import deque
C=deque([A[0]])

for i in range(1,N):
    if i%2==1:
        C.append(A[i])
        ans+=min(C[-2],C[0])
        
    else:
        C.appendleft(A[i])
        ans+=min(C[1],C[-1])
    
    #print(C)
    #print(ans)

print(ans)
#%%
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
A.sort()
arr = []

for _ in range(2):
    temp = A.pop()
    arr.append(temp)
    
ans += arr[0]

for i in range(N - 2):
    t = min(arr[-1], arr[-2])
    ans += t
    p = A.pop()
    arr.append(p)
    
print(ans)
n = int(input())

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

print(a[-1] + a[-2]*(n-2))
from collections import deque
n = int(input())
numlist = sorted(deque(map(int,input().split())))
ans = 0
max = [numlist.pop(),1]
for i in range(n-1):
    num = numlist.pop()
    if num == max[0]:
        ans += max[0]
        max[1] += 1

    else:
        ans += max[0]
        max[1] -= 1
        if max[1] == 0:
            max[0] = num;max[1] = 1
print(ans)
import heapq
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
q=[A[0],A[0]]
heapq.heapify(q)

ans=0
for a in A[1:]:
    one=heapq.heappop(q)
    two=heapq.heappop(q)
    ans+=max(one,two)
    heapq.heappush(q,a)
    heapq.heappush(q,a)
    heapq.heappush(q,one)
    heapq.heappush(q,two)
print(ans)
n=int(input())
m=list(map(int, input().split()))
ans=0

m.sort(reverse=True)

for _ in range(1,n):
  ans=ans+m[_-1]
  
print(ans)
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)

if n <= 3:
  print(a[:-1])
else:
  ans = sum(a[:1])
  for i in range(3, n):
    ans += max(a[i-2], a[i-1])
  print(ans)
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
for i in range(1,n):
  ans += A[i-1]
print(ans)
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce

def main():

    n = int(input())
    lists = list(map(int, input().split()))
    lists.sort(reverse=True)
    print(sum(lists[:-1]))

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

main()
#ABC174D - 絶対違う
n = int(input())
l = list(map(int,input().split()))
ans = 0
l2 = sorted(l)
l2.pop(0)
for i in l2:
  ans += i
print(ans)
n=int(input())
m=[int(x) for x in input().split()]
m=sorted(m, reverse=True)
c=0
mini=m[0]
for i in range(1, len(m)):
  c+=mini
  if mini > m[i]:
    mini=m[i]
print(c)
N = input()


a = map(int, input().split())
a = sorted(a, reverse=True)
result = 0
pre = a[0]
for i in a[1:]:
	result += min(a[0], pre)
	pre = i
print(result)
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)
A.pop()
print(sum(A))
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

ans=0
ans_list=[]
for i in range(N):
    if i == 0:
        ans+=0
        ans_list.append(A[i])
    elif i== 1:
        ans+=A[i-1]
        ans_list.append(A[i])
    else:
        ans+=ans_list[1]

print(ans)
n = int(input())

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

nums.pop(-1)
print(sum(nums))
n = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
max1i = n-1
max2 = 0
for i in range(n) :
    if A[i] == A[0] :
        continue
    max2 = A[i]
    max1i = i
    break

print(A[0]*max1i+max2*(n-i-1))
n = int(input())
a_li = list(map(int,input().split()))
a_li.sort(reverse=1)
if n == 2:
    print(a_li[0])
    exit()
if n == 3:
    print(a_li[0]+a_li[1])
    exit()

m = a_li[0]
l = a_li[1]
r = a_li[2]
ans = 0
ans += a_li[0]+a_li[1]
for i in range(3,n):
    if l > r:
        ans += l
        l = a_li[i]
    else:
        ans += r
        r = a_li[i]
print(ans)
n = int(input())
a = list(map(int, input().split()))

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

answer = sum(A) - min(A)
print(answer)
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
a=get_array()
b=sum(a)
print(b-1)
import collections

N = int(input())
Mylist = input().split()
Mylist = [int(s) for s in Mylist]
Mydict = collections.Counter(Mylist)

ANS = 0
lastKey = 0
amari = 0

for keys in Mydict.keys():
    tukaukazu = amari-Mydict[keys]
    if tukaukazu > 0:
        ANS += lastKey*tukaukazu
        amari = tukaukazu
    else:
        ANS += lastKey*amari + keys*-1*tukaukazu
        amari = -1*tukaukazu
        lastKey = keys

print(ANS-min(Mylist))
n = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)

ans = A[0]
for i in range(n-2):
    print((i//2) + 1)
    ans += A[(i//2) + 1]

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]

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

if N==2:
  print(A[-1])
  exit()
  
ans=0
for i in range(N-1):
  ans+=A[(i-2)//2]
  
print(ans)
def main(N, A):
    # 席順
    l = A[:2]
    # 心地よさ合計
    ans = A[0]
    # 最小値の初期値
    minimum = A[0]
    memo_a = A[1]

    for a in A[2:]:
        minimum = min(minimum, memo_a)
        ans += minimum
        # l.insert(l.index(minimum), a)
        memo_a = a
    print(ans)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse = True)
    main(N, A)
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
t=[A[0],A[1]]
ans=A[0]
for i in range(2,N):
    if t[1]>=t[-1]:
        ans+=t[1]
    else:
        t.append(A[i])
        ans+=t[-1]
print(ans)
def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(sum(a) - min(a))
if __name__=='__main__':
    main()
#!/usr/bin/env python3

import collections
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

C = collections.Counter(A)

if N == 2:
    print(A[0])
    exit()
ret = A[0]
cnt = 2

C = sorted(C.items())[::-1]
for n, c in C:
    if cnt + c > N:
        ret += n*(N-cnt)
        break
    else:
        ret += n*c*2
        cnt += n

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

s = 0

for i in range(1, n):
    s += min(arr[0], arr[i - 1])




print(s)
# -*- coding: utf-8 -*-

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

A_list = sorted(A_list, reverse=True)

print(A_list[0]+A_list[1]*(N-2))
'''Template Starts'''

def _int():
    return int(input())
    
def _ints():
    return map(int, input().split())
    
def _str():
    return input()
    
def _list():
    return list(_ints())
    
'''Template Ends'''

n = _int()
l = sorted(_list())
print(sum(l[2:] + [l[len(l) - 2]]))
n = int(input())
a=list(map(int,input().split()))
b = sorted(a)
b = b[::-1]
print(b)
x = 0
y = 0
z = 0
for i in range(n):
    y += sorted([x, z])[0]
    z = x
    if i == 0:
        x = b[0]
        z = b[0]
    elif i < 3:
        if b[i] < x:
            x = b[i]
print(y)
from bisect import bisect, insort

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

sa = sorted(A)

count = 0
rs = sorted(sa[1:], reverse=True)
for i in rs:
    ba = bisect(sa, i)
    count += sa[ba-1]

print(count)
n = int(input())
dat = list(map(int, input().split()))
dat.sort(reverse=True)
print(sum(dat[:n-1]))
N = int(input())
A_LIST = list(map(int, input().split()))

circle = [max(A_LIST)]
pts = 0
for a in sorted(A_LIST)[::-1][1:]:
    pts += min(circle[0], circle[-1])
    if len(circle) // 2:
        circle += [a]
    else:
        circle = [a] + circle
        
print(pts)
n = int(input())
L = list(map(int,input().split()))
L.sort()
print(sum(L[1:]))
input()
lst=[int(i) for i in input().split()]
sm=0 
mn=99999999999
for i in lst :
    mn=min(i,mn)
    sm=sm+i

print(sm-mn)
N = int(input())
S = input().split()
A = []
for s in S:
    A.append(int(s))
A.sort(reverse=True)

result = 0
count = 0
for i in range(N-1):
    if i == 0:
        result+=A[count]
        count+=1
    else:
        result+=A[count]
        if count%2 == 0:
            count +=1
print(result)
## coding: UTF-8
N = int(input())
A = list(map(int,input().split()))

A = sorted(A, reverse = True)
#print(N, A)

ans = 0

if(N == 2):
    print(A[0])
elif(N == 3):
    print(A[0] + A[1])
elif(N == 4):
    print(A[0] + A[1] + A[1])
elif(N == 5):
    print(A[0] + A[1] + A[1] + A[2])
else:
    ans += A[0]
    ans += A[1]
    for i in range(2, N-3):
        ans += A[i]
    ans += A[1]
    ans += A[2]
    print(ans)
# coding: utf-8

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

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

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

if N%2 != 0:
    ans += A[(N-2)//2]

print(ans)
def main():
    n = int(input())
    comp = list(map(int, input().split()))
    comp.sort(reverse=True)
    
    fin = n - 2
    p = comp[0]
    for i in range(1, n):
        if fin == 1:
            p += comp[i+1]
            break
        elif fin == 0:
            break

        p += comp[i]*2
        fin -= 2

    print(p)



if __name__ == '__main__':
    main()
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
res = 0
for i in range(1, N):
    if i == 1:
        res += A[i-1]
        continue
    res += min(A[i-1], A[i-2])
print(res)
import math
import sys

def main():

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

print(ans)
N = int(input())
a = list(map(int,input().split()))
total=0
for i in range(N):
	total += a[i]
total -= min(a) 
print(total)
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,25):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[insx_list[j-1]-1],reached_list[insx_list[j-1]])
    reached_list.insert(insx_list[j-1], A_list[j])
    mx_cmfrt += cmfrt
    cmfrt = 0
print(mx_cmfrt)
n = int(input())
list =list(map(int, input().split()))

list.sort(reverse=True)

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

ans += a[0]

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

print(ans)
from collections import deque
n = int(input())
numlist = sorted(deque(map(int,input().split())))
ans = 0
for i in range(n-1):
    ans += numlist.pop()
print(ans)
def main():
    n = int(input())
    a_list = sorted(list(map(int, input().split())), reverse=True)
    ans = a_list[0]

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

    print(ans)


if __name__ == "__main__":
    main()
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
C = A[0]
for i in range(2,N):
  C = C+max(A[i-1],A[i-2])
print(C)
n = input()
friendliness = [int(item) for item in input().split()]
friendliness.sort(reverse=True)
def of_ans():
  sum_ = 0
  for idx in range(len(friendliness)):
  	sum_ += friendliness[- idx // 2]
  return sum_
print(of_ans())
n = int(input())
print(sum(sorted(map(int,input().split()))[1:]))
N = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
score = nums[0] + sum(nums[1:N//2])
if N%2 != 0:
  score += nums[N//2]
print(score)
N = int(input())
l = list(map(int, input().split()))
print(sum(l) - min(l))
n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a, reverse=True)

r = a_sorted[0]
i = 2
while i > 1 and i < n:
    r = r + min(a_sorted[i-1], a_sorted[i-2])
    i += 1

print(r)
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n=I()
a=L()

a.sort(reverse=True)
print(sum(a[:n-1]))
n = int(input())

a = list(map(int, input().split()))
s = sum(a) - min(a)
print(s)
n = int(input())
a = list(map(int, input().split())  )
a.sort()
print( sum(a[2:]) + a[-2] )
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
a=sum(arr)
b=min(arr)
print(a-arr[0])