from heapq import heapify, heappop, heappush

N = int(eval(input()))

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

A.sort(reverse = True)

#print(A)

ans = A[0]

Q = [(-A[1],-A[0]),(-A[1],-A[0])] #一つ目が大きいほうへ入れる

heapify(Q)

for i in range(2,N):

  nxt = A[i]

  s,t = heappop(Q)

  s *= -1; t*= -1 #正に戻す

  #print(s,ans)

  ans += s

  heappush(Q,(-nxt,-s))

  heappush(Q,(-nxt,-t))

  #print(Q)

print(ans)





         

         
N = int(eval(input()))

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

A.sort(reverse=True)

B = [A[0]]

for i in range(N-1):

  B.append(A[i+1])

  B.append(A[i+1])

#print(B)

ans = 0

for i in range(N-1):

  ans += B[i]

print(ans)
from heapq import heapify, heappop, heappush

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
# print(A)
ans = A[0]
Q = [(-A[1], -A[0]), (-A[1], -A[0])]  # 一つ目が大きいほうへ入れる
heapify(Q)
for i in range(2, N):
    nxt = A[i]
    s, t = heappop(Q)
    s *= -1
    t *= -1  # 正に戻す
    # print(s,ans)
    ans += s
    heappush(Q, (-nxt, -s))
    heappush(Q, (-nxt, -t))
    # print(Q)
print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
B = [A[0]]
for i in range(N - 1):
    B.append(A[i + 1])
    B.append(A[i + 1])
# print(B)
ans = 0
for i in range(N - 1):
    ans += B[i]
print(ans)

-from heapq import heapify, heappop, heappush - -# print(A) -ans = A[0] -Q = [(-A[1], -A[0]), (-A[1], -A[0])]  # 一つ目が大きいほうへ入れる -heapify(Q) -for i in range(2, N): -    nxt = A[i] -    s, t = heappop(Q) -    s *= -1 -    t *= -1  # 正に戻す -    # print(s,ans) -    ans += s -    heappush(Q, (-nxt, -s)) -    heappush(Q, (-nxt, -t)) -    # print(Q) +B = [A[0]] +for i in range(N - 1): +    B.append(A[i + 1]) +    B.append(A[i + 1]) +# print(B) +ans = 0 +for i in range(N - 1): +    ans += B[i]