代码
# encoding = utf-8
# 开发者:xxx
# 开发时间: 20:43
# "Stay hungry,stay foolish."
n = int(input())
num_list = list(map(int, input().split()))
total = 0
num_list.sort()
for _ in range(n-1):
num = num_list[0] + num_list[1]
total = total + num
num_list.pop(0)
num_list.pop(0)
num_list.append(num)
num_list.sort()
print(total)