import sys
import heapq
input = sys.stdin.readline
N = int(input())
card_list = []
card_heap = []
for _ in range(N):
heapq.heappush(card_heap, int(input()))
if(len(card_list) == 1):
print(0)
else:
while(len(card_heap) != 1):
card1 = heapq.heappop(card_heap)
card2 = heapq.heappop(card_heap)
heapq.heappush(card_heap, card1+card2)
card_list.append(card1+card2)
print(sum(card_list))