Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.
The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.
When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.
What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_N

-----Output-----
Print the maximum total comfort the N players can get.

-----Sample Input-----
4
2 2 1 3

-----Sample Output-----
7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
A2 = [A[0]]
for a in A[1:]:
    A2.extend([a, a])
ans = 0
for a in A2[:n-1]:
    ans += a
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().split()))

A.sort(reverse=True)

a = deque(A)

arrival = 1
ans = 0

while arrival < N:
    score = a.popleft()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

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

n=N-2
a=A[0]
i=1
while 1<n:
  a+=A[i]*2
  i+=1
  n-=2
print(a if n==0 else a+A[i])

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

print(sum([A[i//2] for i in range(1,N)]))

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


n=int(input())
A=tuple(sorted(map(int,input().split() ),reverse=1))
z=n-2
ans=A[0]
now=1
while z:
    if z==1:print(A[now]+ans);return
    else:
        z-=2
        ans+=A[now]*2
        now+=1
print(ans)

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


# print(n)
# print(a)

sort_a = sorted(a, reverse=True)
# print(sort_a)

now_list = []
next_insert = []
comfort = []
# print('start')
for index, i in enumerate(sort_a):
    if len(now_list) == 0:
        now_list += [i]
        next_insert += [1]
        comfort += [i]
    else:
        if len(next_insert) >= n:
            break
        else:
            next_insert += [1, 1]
            comfort += [i, i]


# print(comfort, next_insert)
print((sum(comfort[:n-1])))


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)

print(ans)


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

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

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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)

def __starting_point():
    main()
__starting_point()

N = int(input())
A = list(map(int,input().split()))*2
A.sort()
print((sum(A[N:-1])))


n = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = A[0] + sum(2 * a for a in A[1:n//2])
if n % 2 == 1:
  ans += A[n//2]
print(ans)

n = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse = True)
ans = 0
if n%2 == 0:
    for i in range(n//2):
        if i == 0:
            ans += a[i]
            continue
        ans += a[i]*2
else:
    for i in range(n//2+1):
        if i == 0:
            ans += a[i]
            continue
        ans += a[i]*2
if n %2== 1:
    ans -= a[i]
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)

import heapq

n=int(input())
a=list(map(int,input().split()))
a=list([x*(-1) for x in a])

heapq.heapify(a)
total=0
total+=(-1)*heapq.heappop(a)

if n%2==1 :
    for i in range(1,n//2+1) :
        if i==n//2 :
            total+=(-1)*heapq.heappop(a)
        else :
            total+=(-2)*heapq.heappop(a)
    print(total)

else :
    for i in range(1,n//2) :
        total+=(-2)*heapq.heappop(a)
    print(total)


import math

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse = True)
    
    A_half = math.ceil(N/2)
    A_pre = A[:A_half]
    A_post = A[A_half:]
    
    ret = sum(A_pre)
    for i in range(len(A_post)-1):
        ret += min(A_pre[i],A_pre[(i+1)%A_half])
        
    print(ret)
    
solve()

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)

from math import floor, log2

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

m = floor(log2(N))
print(sum(A[i//2] for i in range(1, N)))

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)

import sys

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

A.sort()
A.reverse()

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

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

print(ans)


m=len(bin(n:=int(input())))-4;A=sorted([*map(int,input().split())])[::-1];print(2*sum(A[:(x:=2**m-(-n+2**-~m)//2)])-A[0]-n%2*A[x-1])

n = int(input())
a = sorted(list(map(int, input().split())))
s = a[::]
ans = 0
c = 0
for i in range(n-1):
    if i == 0:
        ans += s.pop()
    else:
        if c == 0:
            ans += s[-1]
            c += 1
        elif c == 1:
            ans += s.pop()
            c = 0

print(ans)

n=int(input())
a=sorted(list(map(int, input().split())), reverse=True)
cur=1
cnt=0
ans=a[0]
for i in range(1, n-1):
    ans+=a[cur]
    cnt+=1
    if cnt==2:
        cur+=1
        cnt=0
print(ans)

n=int(input())
a=sorted([int(x) for x in input().split()],reverse=True)
ans=a[0]
cnt=idx=1
while idx<n-1:
  for i in range(2):
    ans+=a[idx]
    cnt+=1
    if cnt==n-1: break;
  else:
    idx+=1
    continue
  break
  
print(ans)

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
num = 2
idx = 1
while num<n:
    if num+1==n:
        ans += a[idx]
        num += 1
    else:
        ans += a[idx]*2
        num += 2
        idx += 1
print(ans)

def ans():
    from math import floor
    N = int(input())
    A = [0] + list(map(int, input().split()))
    A = sorted(A)

    sum_conf = 0
    for k in range(1, N):
        sum_conf += A[N - floor(k / 2)]

    print(sum_conf)


def __starting_point():
    ans()
__starting_point()

N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
print(sum([A[(i+1)//2] for i in range(N-1)]))

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

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

A.sort(reverse=True)

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


from collections import deque

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

q = deque()
q.append(a[0])
ans = 0
for i in range(1, n):
    b = q.popleft()
    ans += b
    b = min(b, a[i])
    for _ in range(2):
        q.append(b)
print(ans)


import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as H
  
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())
def rec(h, w): return [[0] * w for i in range(h)] 

n = I()
xs = Is()

xs = sorted(xs, reverse=True)

seats = [-xs[0]]
H.heapify(seats)

ans = 0
for x in xs[1:]:
  ans -= H.heappop(seats)
  H.heappush(seats, -x)
  H.heappush(seats, -x)

print(ans)

N = int(input())
An = list(map(int, input().split()))
An.sort(reverse=True)
answer = 0
t = N-1
for i, Ai in enumerate(An):
    lim = 2
    if i==0:
        lim = 1
    for j in range(lim):
        if t > 0:
            answer += Ai
        t -= 1
print(answer)


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

if n % 2 == 0:
  cnt = n // 2
  cnf = a[0] + sum(a[1:cnt]) * 2

else:
  cnt = n //2
  cnf = a[0] + sum(a[1:cnt]) * 2 + a[cnt]

print(cnf)


n=int(input())
A=list(map(int, input().split()))
A=sorted(A, reverse=True)
ans=0
for i in range(1,n):
    ans+=A[i//2]
print(ans)

def chat_in_a_circle():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    res = A.pop(-1)
    t = len(A) % 2 == 0
    a = 0
    for i in range(len(A) // 2):
        a = A.pop(-1)
        res += a*2
    if t:
        res -= a
        
    print(res)

chat_in_a_circle()

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

list.sort(A, reverse=True)
ans = 0

for i in range(N-1):
#    print(A[math.ceil(i/2)])
    ans += A[math.ceil(i/2)]

print(ans)


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

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

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

x = A[N-1]

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

print(x)


def main():
	N = int(input())
	friendliness = [int(a) for a in input().split(" ")]

	friendliness.sort(reverse=True)
	put = 1
	comfort = 0
	for i in range(len(friendliness)):
		if i == 0:
			put += 1
			comfort += friendliness[0]
		elif put + 2 <= len(friendliness):
			put += 2
			comfort += 2 * friendliness[i]
		else:
			comfort += (len(friendliness) - put) * friendliness[i]
			break

	print(comfort)

main()

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

ans = 0
cnt = 1
# 最大値は一回だけ
ans += A[0]

# N-2個は、2,2,3,3,..i,i,...のように取る
flag = False
for i in range(1, len(A)-1):
    ans += A[cnt]
    if flag == False:
        flag = True
    else:
        flag = False
        cnt += 1
print(ans)

from collections import deque

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

n = int(input())
friendry = list(map(int,input().split()))
friendry.sort()
friendry.reverse()
# print(friendry)
ans = 0
t = n-1
for i in range(n-1):
    lim = 2
    if(i == 0):
        lim = 1
    for j in range(lim):
        if(t > 0):
            ans += friendry[i]
            t -= 1

print(ans)



n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
p = 0
ans = 0
for i in range(n):
  if i==0:continue
  ans += a[p]
  if i%2==1:
    p += 1
print(ans)

n=int(input())
a=sorted(list(map(int,input().split())))
ans=a.pop()
for i in range(n//2-1):
    ans+=2*a.pop()
if n%2==1:
    ans+=a.pop()
print(ans)

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


n = int(input())
a = list(map (int,input().split()))
a.sort()
if n % 2 == 0:
    print((sum(a)-sum(a[:n//2]))*2-max(a))
else:
    print((sum(a)-sum(a[:n//2]))*2-max(a)- a[n//2])

import sys
import re
import queue
import collections
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
	N = i_input()
	A = i_list()

	list.sort(A)
	sum = 0
	for i in range(1,N):
		sum += A[N-1 - floor(i/2)]

	print(sum)

	return

def __starting_point():
	main()
__starting_point()

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

A.sort()
retval = 0
for i in range(1,N):
  retval+=A[N-i//2-1]
  #print(N-i//2-1)
print(retval)

n = int(input())
a_list = sorted([int(x) for x in input().split()])
ans = a_list.pop()
n -= 2
while n > 0:
    a = a_list.pop()
    ans += a
    n -= 1
    if n > 0:
        ans += a
        n -= 1
print(ans)

import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
A = LI()

A.sort(reverse=True)
half, isOdd = divmod(len(A),2)

ans = A[0]
for i in range(1,half):
    ans += 2 * A[i]

if isOdd == 1:
    ans += A[half]

print(ans)

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

A.sort(reverse = True)

ans = 0

i = 0  # 何人目のフレンドリーさがプラスされるか
nokori = N - 1 # 残り入れなければならない人数
while nokori > 0:
    if i == 0:  # 最もフレンドリーな人は初めに入れる
        ans += A[i]
        nokori -= 1
    else:
        if nokori == 1:
            ans += A[i]
            nokori -= 1
        else:
            ans += 2 * A[i]
            nokori -= 2
    i += 1

print(ans)


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

N-=1
i=1
koko=A[0]
f=0
while 1:
  for _ in range(2):
    N-=1
    if N==0:
      f=1
      break
    koko+=A[i]
  if f==1:
    break
  i+=1
print(koko)

n = int(input())
a = list(map (int,input().split()))
a.sort()
if n % 2 == 0:
    print((sum(a)-sum(a[:n//2]))*2-max(a))
else:
    print((sum(a)-sum(a[:n//2]))*2-max(a)- a[n//2])

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

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

print(ans)


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

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

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

for x in A[1:]:
    if cnt == N - 1:
        break
    if cnt == N - 2:
        ans += x
        cnt += 1
        # 奇数の場合
    else:
        ans += 2 * x
        cnt += 2
print(ans)

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

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(reverse=True)
circle =[]

sum_val = 0
for idx in range(1, len(A)):
    sum_val += A[idx//2]
    # circle, val = insert_val(circle, a)
    # sum_val += val

print(sum_val)



def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    ans = a[0]
    t = N - 2

    for i in range(1, N):
        for _ in range(2):
            if t > 0:
                ans += a[i]
                t -= 1
    print(ans)
        

def __starting_point():
    main()
__starting_point()

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

if n % 2 == 0:
    print(sum(A[:n//2] * 2) - A[0])
else:
    print(sum(A[:n//2] * 2) - A[0] + A[n//2])

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
a = sorted(a)[::-1]
ans = sum(a[:(n+1)//2])*2-a[0]
ans = ans if n%2==0 else ans-a[(n+1)//2-1]

print(ans)


import heapq

N = int(input())
A = [int(x) * -1 for x in input().split()]
heapq.heapify(A)
conf = heapq.heappop(A) * -1

for i in range(N - 2):
    feel = heapq.heappop(A) * -1
    conf += feel
    if i % 2 == 0:
        heapq.heappush(A, feel * -1)

print(conf)


N = int(input())
A = list(map(int, input().split()))
B = []
for a in A:
    B.append(a)
    B.append(a)
B.sort()
B.pop()
ans = 0
for i in range(N - 1):
    ans += B.pop()
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=list(map(int,input().split()))
A.sort()
ans=0
for i in range(N-1):ans+=A[N-(i+1)//2-1]
print(ans)

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

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

n=N-2
a=A[0]
i=1
while 0<n:
  if n==1:
    a+=A[i]
    break
  a+=A[i]*2
  i+=1
  n-=2
print(a)

n = int(input())
p_list = input().split()
p_list = map(int,p_list)
p_list = sorted(p_list,reverse=True)
ans_list = []
ans = 0
for i in range(0,len(p_list)):
  if i!=0:
    ans_list.append(p_list[i])
    ans_list.append(p_list[i])
  else:
    ans_list.append(p_list[i])
for i in range(0,n-1):
	ans += int(ans_list[i])
print(ans)

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

import math

n = int(input())
f = list(map(int,input().split()))
f.sort()
ans = 0

for i in range(1,n):
    ans += f[n-math.floor(i/2)-1]

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]-f[0]

print(ans)


import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
A = LI()

A.sort(reverse=True)
# print(A)
# half = math.ceil(len(A)/2)
q, mod = divmod(len(A),2)

if mod == 0:
    ans = A[0]
    for i in range(1,q):
        ans += 2 * A[i]
else:
    ans = A[0]
    for i in range(1,q):
        ans += 2 * A[i]
    ans += A[q]

print(ans)

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()
#print(a)
ans=0
from math import floor
for i in range(1,n):
    ans+=a[n-1-floor(i/2)]
    #print(ans)
print(ans)


import math

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

A.sort(reverse=True)

comfortPoint = A[0]

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

print(comfortPoint)


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

a.sort()

arrival = 1
ans = 0

while arrival < N:
    score = a.pop()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

n = int(input())
li_a = list(map(int, input().split()))
li_a.sort(reverse=True)
ans = 0
for i in range(1, n):
    ans += li_a[i//2]
print(ans)


N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0] #最大値だけ1回
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)
ans = A[0]
if n%2 == 0:
    ans += sum(A[1:n//2])*2
else:
    ans += sum(A[1:n//2])*2 + A[n//2]

print(ans)

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

A.sort(reverse=True)

score = [A[0]]
for i in range(1, N):
    for j in range(2):
        score.append(A[i])

    if len(score) >= N:
        break

print((sum(score[:N-1])))


n = int(input())
p = list(map(int, input().split()))
p.sort(reverse=True)
#追加していく際に追加した数の両脇を固める
s = 0
for i in range(1,n):
    s += p[i//2]

print(s)

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[n//2]
  print(ans)

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

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

a.sort(reverse=True)

ans=a[0]
ch=1

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

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

a.sort()

if n % 2 == 0:
    suma = 2*sum(a[-int((n/2)):])-a[-1]
else:
    suma = 2*sum(a[-int(((n+1)/2)):])-a[-1]-a[-int(((n+1)/2))]

print(suma)

from collections import deque

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

q = deque()
q.append(a[0])
ans = 0
for i in range(1, n):
    b = q.popleft()
    ans += b
    b = min(b, a[i])
    for _ in range(2):
        q.append(b)
print(ans)

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


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = list(map(int, read().split()))
    a.sort(reverse=True)
    a = deque(a)
    circle_joined = deque()
    next_score = a.popleft()
    r = 0
    flag = False
    while a:
        circle_joined.append(a.popleft())
        if flag:
            next_score = circle_joined.popleft()
            r += next_score
            flag = False
        else:
            r += next_score
            flag = True
    print(r)

def __starting_point():
    main()

__starting_point()

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

a.sort(reverse=True)

cnt=a[0]

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

print(cnt)

import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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

tmp = 0
res = 0

A = sorted(A, reverse=True)
res = A[0] + 2 * sum(A[1:n // 2]) + n % 2 * A[n // 2]

print(res)


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

n=N-2
a=A[0]
i=1
while 1<n:
  a+=A[i]*2
  i+=1
  n-=2
print(a+A[i] if n else a)

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

m = (n + 1) // 2
if n % 2 == 0:
    print(sum(A[:m - 1]) + sum(A[1:m]) + A[m - 1])
else:
    print(sum(A[:m - 1]) + sum(A[1:m]))

N = int(input())
A = 2*list(map(int, input().split()))
A.sort()
print(sum(A[N:-1]))

n=int(input())
a=sorted([int(x) for x in input().split()],reverse=True)
ans=0
for i in range(n-1):
  ans+=a[(i+1)//2]
print(ans)

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

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

print(ans)

n=int(input())
a=sorted([int(x) for x in input().split()],reverse=True)
ans=sum([a[(i+1)//2] for i in range(n-1)])
print(ans)

N = int(input())

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

ans = 0
A.sort(reverse=True)
#print(A)
ans += sum(A[:(N+1)//2-1])
for i in range((N+1)//2 - 1):
    ans += min(A[i],A[i+1])
    
if N%2 == 0:
    ans += A[N//2 - 1]

print(ans)

import heapq as hq

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

a.sort()
p = a.pop()
q = []
hq.heappush(q, (-p, -p))
ans = 0
for _ in range(n - 1):
    p = a.pop()
    b1, b2 = hq.heappop(q)
    ans += -b1
    hq.heappush(q, sorted((b1, -p), reverse=True))
    hq.heappush(q, sorted((b2, -p), reverse=True))
print(ans)


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


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


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

index_val = int(N//2)
ans += a[0]
for i in range(1, index_val):
    ans += (2 * a[i])
if N % 2 != 0:
    index_val = N//2
    ans += a[index_val]

print(ans)