peterverebics/CodeNet_Python_118 huggingface dataset:
a=int(input())
cAC=0
cWA=0
cTLE=0
cRE=0
for i in range(a):
    b=input()
    if b=="AC":
        cAC+=1
    elif b=="WA":
        cWA=1
    elif b=="TLE":
        cTLE+=1
    elif b=="RE":
        cRE+=1
print("AC×",cAC)
print("WA×",cWA)
print("TLE×",cTLE)
print("RE×",cRE)
n = int(input())
a = 0
b = 0
c = 0
d = 0
if n > 0:
  for i in range(n):
    S =  str(input())
    if S == 'AC':
      a += 1
    if S == 'WA':
      b += 1
    if S == 'TLE':
      c += 1
    if S == 'RE':
      d += 1
print('AC × '+str(a))
print('WA × '+str(b))
print('TLE × '+str(c))
print('RE × '+str(d))
N=int(input())
S=[input() for i in range(N)]
x=S.count('AC')
y=S.count('WA')
z=S.count('TLE')
w=S.count('RE')
X="AC x []".format(x)
Y="WA x []".format(y)
Z="TLE x []".format(z)
W="RE x []".format(w)
print(X)
print(Y)
print(Z)
print(W)
n=int(input())
a=0
w=0
t=0
r=0

for i in range(n) :
    s=input()
    if s[0]=='A' :
        a+=1
    elif s[0]=='W' :
        w+=1
    elif s[0]=='T' :
        t+=1
    else :
        r+=1

print('AC　'+'×'+'　{}'.format(a))
print('WA　'+'×'+'　{}'.format(w))
print('TLE　'+'×'+'　{}'.format(t))
print('RE　'+'×'+'　{}'.format(r))
t=int(input())
f=[]
for i in range(t):
    s=input()
    f.append(s)
print("AC"+''+'*'+''+str((f.count("AC"))))
print("WA"+''+'*'+''+str((f.count("WA"))))
print("TLE"+''+'*'+''+str((f.count("TLE"))))
print("RE"+''+'*'+''+str((f.count("RE"))))
n = int(input())
Sn = []

for i in range(n):
    Sn.append(input())

ac = Sn.count('AC')
wa = Sn.count('WA')
tle = Sn.count('TLE')
re = Sn.count('RE')

print('AC × {}'.format(ac))
print('WA × {}'.format(wa))
print('TLE × {}'.format(tle))
print('RE × {}'.format(re))
import collections
N = int(input())
S = [input() for i in range(N)]
c = collections.Counter(S)
print("AC","×",c['AC'])
print("WA","×",c['WA'])
print("TLE","×",c['TLE'])
print("RE","×",c['RE'])
t=int(input())
d={'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(t):
    s=input()
    d[s]+=1

for i in d:
    print(i + ': ' + str(d[i]))
N = int(input())
S = [input() for _ in range(N)]
ls = ["AC","WA","TLE","RE"]
for i in range(4):
  print("{} × {}".format(ls[i],S.count(ls[i])))
n = int(input())
s = [input() for _ in range(n)]

cnt_ac = s.count('AC')
cnt_wa = s.count('WA')
cnt_tle = s.count('TLE')
cnt_re = s.count('RE')

print(f'AC×{cnt_ac}')
print(f'WA×{cnt_wa}')
print(f'TLE×{cnt_tle}')
print(f'RE×{cnt_re}')
n = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    else:
        re += 1
print("AC × " + str(ac))
print("WA × " + str(wa))
print("TLE × " + str(tle))
print("RE × " + str(re))
N=int(input())
AC=0
TLE=0
WA=0
RE=0
for i in range(N):
    x=input()
    if x == "AC":
        AC += 1
    elif x == "TLE":
        TLE+=1
    elif x=="WA":
        WA+=1
    else:
        RE+=1
print("AC x " + str(AC))
print("TLE x " + str(TLE))
print("WA x " + str(WA))
print("RE x " + str(RE))
n=int(input())
a=0
w=0
t=0
r=0

for i in range(n) :
    s=input()
    if s[0]=='A' :
        a+=1
    elif s[0]=='W' :
        w+=1
    elif s[0]=='T' :
        t+=1
    else :
        r+=1

print('AC '+'×'+' {}'.format(a))
print('WA '+'×'+' {}'.format(w))
print('TLE '+'×'+' {}'.format(t))
print('RE '+'×'+' {}'.format(r))
n = int(input())
for _ in range(n) :
    l = list(input())
print('AC x ' + str(l.count('AC')))
print('WA x ' + str(l.count('WA')))
print('TLE x ' + str(l.count('TLE')))
print('RE x ' + str(l.count('RE')))
from collections import Counter as ct

n = int(input())
s = ct([input() for _ in range(n)])
print("AC x " + str(s["AC"]))
print("WA x " + str(s["wA"]))
print("TLE x " + str(s["TLE"]))
print("RE x " + str(s["RE"]))
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    a = input()
    if a == "AC":
        AC += 1
    elif a == "WA":
        WA += 1
    elif a == "TLE":
        TLE += 1
    elif a == "RE":
        RE += 1
print(f"AC ✖︎ {AC}")
print(f"WA ✖︎ {WA}")
print(f"TLE ✖︎ {TLE}")
print(f"RE ✖︎ {RE}")
ac=0
wa=0
tle=0
re=0
n=int(input())
for i in range (0,n):
    s=input()
    if s=='AC' :
        ac=ac+1
    elif s=='WA' :
        wa=wa+1
    elif s=='TLE' :
        tle=tle+1
    else :
        re=re+1
print("AC × "+str(ac))
print("WA × "+str(wa))
print("TLE × "+str(tle))
print("RE × "+str(re))
n = int(input())
d = [input() for i in range(n)]
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
  if d[i] == 'AC':
    ac = ac + 1
  elif d[i] == 'WA':
    wa = wa +1
  elif d[i] == 'TLE':
    tle = tle +1
  else:
    re = re +1

print('AC ×', ac)
print('WA ×', wa)
print('TLE ×', tle)
print('RA ×', re)
from sys import stdin,stdout
import math
from collections import Counter,defaultdict
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()

def case():
    a=b=c=d=0
    for i in range(IN()):
        s=S()
        if s=="AC":a+=1
        elif s=="TLE":b+=1
        elif s=="WA":c+=1
        else:d+=1
    print("AC","x",a)
    print("AC","x",c)
    print("AC","x",b)
    print("AC","x",d)
for _ in range(1):
    case()
c = int(input())
j =  [0]*4
for i in range(c):
  a = input()
  if a == "AC":
    j[0] += 1
  elif a == "WA":
    j[1] += 1
  elif a == "TLE":
    j[2] += 1
  else:
    j[3] += 1
    
print("AC × "+ str(j[0]))
print("WA × "+ str(j[1]))
print("TLE × "+ str(j[2]))
print("RE × "+ str(j[3]))
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    else:
        re += 1
print("AC ✕ "+str(ac))
print("WA ✕ "+str(wa))
print("TLE ✕ "+str(tle))
print("RE ✕ "+str(re))
n=int(input())
a=[0]*4
b=""
for i in range(n):
    b=input()
    if b=="AC":
        a[0]+=1
    elif b=="WA":
        a[1]+=1
    elif b=="TLE":
        a[2]+=1
    elif b==1:
        a[3]+=1

print("AC","x",a[0])
print("WA","x",a[1])
print("TLE","x",a[2])
print("RE","x",a[3])
n = int(input())
data = [input() for _ in range(n)]
a = data.count("AC")
b = data.count("WA")
c = data.count("TLE")
d = data.count("RE")
print("AC × " + str(a))
print("WA × " + str(b))
print("TLE × " + str(c))
print("RE × " + str(d))
a = int(input())
str_list = [input() for _ in range(a)]
print("{} {}".format("AC × ", str_list.count('AC')))
print("{} {}".format("WA × ", str_list.count('WA')))
print("{} {}".format("TLE × ", str_list.count('TLE')))
print("{} {}".format("RE × ", str_list.count('RE')))
N = int(input())
s = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
  print('{0}×{1}'.format(v, s.count(v)))
n = int(input())
a = ["AC"] * n
c = [0]*4

for i in range(n):
  a[i] = input()
  if(a[i]=="AC"):
    c[0] += 1
  if(a[i]=="WA"):
    c[1] += 1
  if(a[i]=="TLE"):
    c[2] += 1
  if(a[i]=="RE"):
    c[3] += 1

print("AC × " +str(c[0]))
print("WA × " +str(c[1]))
print("TLE × " +str(c[2]))
print("RE × " +str(c[3]))
N = int(input())
for i in range(N):
  s = list(input())
print('AC x',s.count('AC'))
print('TLE x',s.count('TLE'))
print('RE x',s.count('RE'))
print('WJ x',s.count('WJ'))
n = int(input())
S = []
a = 0
t = 0
w = 0
r = 0
for _ in range(n):
    S.append(input())
for i in range(n):
  if S[i]=="AC":
    a += 1
  elif S[i]=="TLE":
    t += 1
  elif S[i]=="WA":
    w += 1
  else:
    r += 1
a = str(a)
w = str(w)
t = str(t)
r = str(r)
print("ACx"+a)
print("WAx"+w)
print("TLEx"+t)
print("REx"+r)
n=int(input())
s=[]
for i in range(n):
  s.append(input())
print("AC"+" × "+str(s.count("AC")))
print("WA"+" × "+str(s.count("WA")))
print("TLE"+" × "+str(s.count("TLE")))
print("RE"+" × "+str(s.count("RE")))
N = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for _ in range(N):
    s = input()

    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "re":
        re += 1

print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}")
n = int(input())
searchWord = ['AC','WA','TLE','RE']
wordCountDict = {letter : 0 for letter in searchWord}
for i in range(n):
    word = input()
    if word in searchWord:
        wordCountDict[word] += 1

for key, value in wordCountDict.items():
    print(f'{key} × {value}')
N=int(input())
S = []
for _ in range(N):
    S.append(input())
a=0
b=0
c=0
d=0
for i in S:
  if i=='AC':
    a+=1
  elif i=='WA':
    b+=1
  elif i=='TLE':
    c+=1
  else:
    d+=1
print('AC×'+str(a))
print('WA×'+str(b))
print('TLE×'+str(c))
print('RE×'+str(d))
a=int(input())

b=0
c=0
d=0
e=0

for i in range(a):
  name=input()

  if name=='AC':
    b+=1
  elif name=='WA':
    c+=1
  elif name=='TLE':
    d+=1
  elif name=='RE':
    e+=1

print('AC x '+str(b))
print('WA × '+str(c))
print('TLE × '+str(d))
print('RE × '+str(e))
N = int(input())
list = [input() for i in range(N)]

print("AC ×", list.count("AC"))
print("WA ×", list.count("WA"))
print("TLE ×", list.count("TLE"))
print("RE ×", list.count("RE"))
N=int(input())
S=[input() for i in range(N)]
AC=0
WA=0
TLE=0
RE=0
for i in S:
    if i =="WA":
        WA+=1
    elif i=="AC":
        AC+=1
    elif i=="TLE":
        TLE+=1
    else:
        RE+=1
print("AC x　"+str(AC))
print("WA x "+str(WA))
print("TLE x",TLE)
print("RE x",RE)
N = int(input())
L =[]
for i in range(N):
    S = input()
    L.append(S)

print("AC * " + str(L.count("AC")))
print("WA * " + str(L.count("WA")))
print("TLE * " + str(L.count("TLE")))
print("RE * " + str(L.count("RE")))
n = (int)(input())
C_0 = 0
C_1 = 0
C_2 = 0
C_3 = 0
for i in range(n):
    s = input()
    if s == "AC":
        C_0 += 1 #means C_0 = C_0 + 1
    if s == "WA":
        C_1 += 1
    if s == "TLE":
        C_2 += 1
    else:
        C_3 += 1

print('AC x {}'.format(C_0)) #{}のところにC_0の値が出力される
print('WA x {}'.format(C_1))
print('TLE x {}'.format(C_2))
print('RE x {}'.format(C_3))
n = int(input())
ans = [0,0,0,0]

for i in range(n):
  tmp = input()
  if tmp == "AC":
    ans[0] += 1
  elif tmp == "WA":
    ans[1] += 1
  elif tmp == "TLE":
    ans[2] += 1
  else:
    ans[3] += 1
    
print("AC ×",ans[0])
print("WA ×",ans[1])
print("TLE ×",ans[2])
print("RE ×",ans[3])
import copy
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
d = deque()
c = 0
count = 2
ans = 0

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


ans+=A[0]
if (N-2)%2==0:
    ans+=sum(A[1:int((N-2)/2)+1])*2
else:
    ans+=sum(A[1:int((N-3)/2)+1])*2
    ans+=A[int((N-1)/2)]


print(ans)
N = int(input())
A = [int(_) for _ in input().split()]
ans = 0
AA = A + A
AA.sort(reverse=True)

# sumする
for i in range(1, N):
    ans += AA[i]

print(ans)
import sys
n=int(input())
a=list(map(int,input().split()))
def nibai(n):
  return n*2
a.sort(reverse=True)
sc=a[0]
if n==2:
  print(sc)
  sys.exit() 
a=a[1:]
b=list(map(nibai,a))
sc+=sum(b[:(n//2)-1])
if n%2==0:
  print(sc)
else:
  print(sc+a[(n//2)-1])
N = int(input())

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

A.sort(reverse=True)

gain = 0

n = 1
while n <= N-1:
  if n % 2:
    gain += A[(n-1)//2]
    # print(f'{n}, added {A[(n-1)//2]}')
  else:
    gain += A[(n+1)//2]
    # print(f'{n}, added {A[(n+1)//2]}')
  n += 1

print(gain)
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//2]
    print(s)
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 20:47:07 2020

@author: ezwry
"""
import math

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

a.sort(reverse=1)

ans=[]

for i in range(n-1):
    jyun=math.ceil(i/2)
    ans.append(a[jyun])

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

A.sort(reverse=True)

res = 0

res += A.pop(0)

count = 1

for i in range(N):
    for _ in range(2):
        if count < N - 1:
            res += A[i]
            count += 1

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

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

print (ans)
n=int(input())
l=sorted(list(map(int,input().split())),reverse=1)
from heapq import heapify, heappop, heappush
h=[-l[0]]

ans=0
for i in range(1,n):
    p=-heappop(h)
    ans+=p
    heappush(h,-l[i])
    heappush(h,-l[i])
print(ans)
n = int(input())
m=list(map(int,input().split()))
m.sort(reverse=True)
k=0
for i in range((n+1)//2-1):
    k+=m[i]

for i in range(1,(n+1)//2):
    k+=m[i]

if n%2==0:
    k+=m[(n+1)//2-1]
print(k)
import heapq

N = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr, reverse = True)
ans = 0
q = []
heapq.heappush(q, -arr[0])

for i in range(1, N):
  tmp = heapq.heappop(q)
  tmp *= -1
  ans += tmp
  heapq.heappush(q, -arr[i])
  heapq.heappush(q, -arr[i])
  
print(ans)
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
S = 0
for i in range(N-1):
    S += A[(i+1)//2]
print(S)
n = int(input())
a = list(map(int,input().split()))
a.sort()
c = a[-1]
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = a[n-2-i]
    c += a1*2
else:
  n2 = n//2
  a3 = a[n-n2-1]
  c += a3
  for i in range(n2-1):
    a2 = a[n-2-i]
    c += a2*2
print(c)
from collections import deque
n = int(input())
a_ls = list(map(int, input().split()))
a_ls.sort(reverse = True)
queue = deque()
queue.append(a_ls[0])
for i in range(1,n):
    queue.append(a_ls[i])
    queue.append(a_ls[i])
ans = 0
for _ in range(n-1):
    ans += queue.popleft()
print(ans)
n,*a = map(int,open(0).read().split())
a.sort(reverse=True)
print(a[0]+sum(a[1:n//2])+sum(a[1:n-n//2]))
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = a[0]
for i in range(2,n):
    ans += a[i//2]

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

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

a = [int(i) for i in input().split()]

a.sort(reverse=True)

kotae = a[0]
for i in range(n-2):
    kotae += a[1 + (i // 2)]

print(kotae)
n = int(input())
l=sorted(list(map(int,input().split())))
an=l[n-1]
x=l[n-2];cr=n-3;cc=0
for i in range(n-3,-1,-1):
  an+=x
  cc+=1
  if cc!=0 and cc%2==0:
    x=l[cr];cr-=1
  #print(an,x,cr)
print(an)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

score = - a[0]
for i in range(n):
    score += a[i // 2]
print(score)
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 = max(A)
print(ans)
n,*l=map(int,open(0).read().split())
from heapq import *
l.sort()
q=[-l.pop()]
a=0
for _ in range(n-1):
  m=heappop(q)
  a-=m
  t=-l.pop()
  heappush(q,t)
  heappush(q,t)
print(a)
import numpy as np
N = int(input())
comfort = list(map(int,input().split()))
comfort_reverse = np.sort(comfort)[::-1]

ans = comfort_reverse[0]

if N > 2:
    for i in range(N-2):
        num = i // 2 + 1
        ans += comfort_reverse[num]

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

n = int(input())
players = [int(x) for x in input().split()]
players.sort(reverse = True)
comfortness = 0
for i in range(n-1):
    comfortness += players[math.ceil(i/2)]

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

A.sort(reverse=True)
syugo = [0]*N
syugo[0] = A[0]
syugo[1] = A[1]
flg = False
ans = A[0]
idx = 1
for i in range(2, N):
    if flg:
        ans += A[idx]
        flg = False
        idx += 1
    else:
        ans += A[idx]
        flg = True

print(ans)
#abc173d
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
res=0
for i in range(1,n):
 res+=l[i//2]
print(res)
from collections import deque

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

Q = deque([0])
comfort = 0
i = 0
while Q:
    if i == n:
        break
    comfort += Q.popleft()
    if i == 0:
        Q.append(a[i])
    elif i > 0:
        Q.append(a[i])
        Q.append(a[i])
    i += 1

print(comfort)
n = int(input())
a = list(map(int, input().split()))*2
a.sort()
print(sum(a[n:-1]))
n=int(input())
a=sorted(list(map(int,input().split())))[::-1]
ans=0
for i in range(1,n):
  ans+=a[i//2]
print(ans)
N=int(input())
A=list(map(int,input().split()))
A.sort()
count=1
ans=A[-1]
id=N-2
while count!=N-1:
    if count+2<=N-1:
        ans+=2*A[id]
        count+=2
        id-=1
    else:
        ans+=A[id]
        count+=1

print(ans)
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse=True)
ans = 0

for i in range(n//2):
    if i == 0:
        ans += li[i]
    else:
        ans += li[i]*2

if n%2 == 1:
    ans += li[i+1]

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

A.sort(reverse=True)
ret = A[0]
c = N - 2
i = 1
while c :
  if c >= 2 :
    ret += A[i] * 2
    c -= 2
  else :
    ret += A[i]
    c -= 1
  i += 1

print(ret)
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
if n >= 2:
   ans = a[0]
for i in range(n-2):
   ans += a[i//2+1]
print(ans)
import math
import sys
from itertools import permutations
input = sys.stdin.readline

N=int(input())
arr=list(map(int,input().split()))
arr.sort(reverse=True)

cur=2
ans=arr[0]
for i in range(1,N):
    if cur>=N:
        break
    ans+=arr[i]
    cur+=1

    if cur>=N:
        break
    ans+=arr[i]
    cur+=1

print(ans)
from collections import deque

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


A.sort(reverse=True)

if N == 2:
    print(A[0])
else:
    ans = A[0]
    friendly_deque = deque()
    friendly_deque.append(A[1])
    friendly_deque.append(A[1])
    
    for i in range(2,N):
        add = friendly_deque.popleft()
        ans += add
        friendly_deque.append(A[i])
        friendly_deque.append(A[i])

    print(ans)
import queue

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
q = queue.Queue()

ans = A[0]
q.put( (A[0], A[1]) )
q.put( (A[0], A[1]) )
for i in range(2, len(A)):
  t = q.get()
  ans += min(t[0], t[1])
  q.put((t[0], A[i]))
  q.put((t[1], A[i]))
  
print(ans)
from heapq import *

N,*A = map(int, open(0).read().split())
ai = [x * (-1) for x in A]
heapify(ai)
ans = heappop(ai) * (-1)
searching = 1
for i in range(N-2):
    if i % 2 == 0:
        temp = heappop(ai) * (-1)
    ans += temp
print(ans)
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
ans = 0
if N >= 2:
    ans += A[0]

if N >= 3:
    idx = 1
    for i in range(N-2):
        ans += A[idx]
        if i % 2 == 1:
            idx += 1

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+1]
print(ans)
n = int(input())
a = list(map(int, input().split()))

a1 = sorted(a, reverse=True)
com = 0

if n == 2:
    com = a1[0]
elif n%2 ==0:
    c = int(n/2)
    com = sum(a1[0:c])
    com += sum(a1[1:c])
else:
    c = int(n//2)
    com += sum(a1[0:c+1])
    com += sum(a1[1:c])
    
print(com)
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
ind = n-1
a.sort()
for i in range(n-1):
    if i%2:
        ans += a[ind]
    else:
        ans += a[ind]
        ind -= 1

print(ans)
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=1)
ans=0+a[0]
cnt=1
for i in range(1,n):
    if cnt<n-2:
        ans+=2*a[i]
        cnt+=2
    elif cnt==n-2:
        ans+=a[i]
        break
    elif cnt==n-1:
        break
print(ans)
n = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)
ans = a[0]

for i in range((n-2)//2):
    ans += a[i+1]*2
    # print(ans)
if (n) % 2 == 1:
   # print(a[i+2], i+2)
    ans += a[i+2]
print(ans)
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
#rint(sum(a[:-1]))

c=0
for i in range(n):
    if i == 0:
        c+=0
    elif i == 1:
        c+=a[0]
    else:
        c+=a[i//2]
print(c)
def main():
    n = int(input())
    A = list(map(int,input().split()))

    A.sort(reverse = True)

    # print(A)
    B = [A[0]]
    for i in A[1:]:
        B.append(i)
        B.append(i)

    print(sum(B[:n-1]))


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


# print(A)

idx = []
for i in range(N + 1 // 2):
    idx.append(i)
    idx.append(i)

idx = idx[::-1]
idx = idx[1:N]
# print(idx)
ans = 0
for i in idx:
    ans += A[i]
print(ans)
a=int(input())
List = list(map(int, input().split()))
List.sort(reverse=True)
res =List[0]
for i in range(1,a-1):
  if i%2 ==0:
    res += List[int(i/2)]
  else:
    res += List[int((i+1)/2)]
print(res)
n = int(input())
a = list(map(int,input().split()));
a.sort()
com = 0;
for k in range(n-1):
    kk = n - (k+1) // 2 - 1
    com += a[kk]
print(com);
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

res = 0
if N % 2 == 0:
    r = N // 2
    for i in range(r):
        res += A[i] * 2
    print(res - A[0])
else:
    r = N // 2 + 1
    for i in range(r):
        res += A[i] * 2
    print(res - A[0] - A[r - 1])
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
A.sort(reverse=True)
N-=1
ans=0
for i,a in enumerate(A):
    if i==0:
        ans+=a
        N-=1
    else:
        if 2<=N:
            ans+=a*2
            N-=2
        elif N==1:
            ans+=a
            N-=1
        elif N==0:
            print ans
            quit()
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
ans = a[0]
for i in range(n-2):
    ans += a[1+(i//2)]

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

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

print(ans)
def solve(A,N):
    A.sort(reverse = True)
    ans = A[0]
    if N % 2 == 0:
        pt = N // 2 - 1
        for i in range(1,pt+1):
            ans += (2 * A[i])
    else:
        pt = (N-1) // 2
        for i in range(1,pt):
            ans += (2 * A[i])
        ans += A[pt]
    return ans

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

    print(solve(A,N))

if __name__ == "__main__":
    main()
n = int(input())
a = map(int,input().split())
a = sorted(a)

result = 0
spots = [a.pop()]

for i in range(n-1):
	x = a.pop()
	result += spots[i]
	spots.append(x)
	spots.append(x)
	
print(result)
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans = 0
for i in range(1,n):
    ans += a[i//2]
print(ans)
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353



N = int(input())

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

A = sorted(A, reverse=True)

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

print(ans)