Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks:  Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.  Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. 

After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 3·10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) — the initial group that is given to Toastman.


-----Output-----

Print a single integer — the largest possible score.


-----Examples-----
Input
3
3 1 5

Output
26

Input
1
10

Output
10



-----Note-----

Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.

Difficulty: EASY
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
n = int(input())
num = [int(i) for i in input().split()]
num = sorted(num)
result = 0
for i in range(n - 1):
	result = result + num[i] * (i + 2)
result = result + num[-1] * n
if n == 1:
	print(num[0])
else:
	print(result)


n = int(input())
group = [int(i) for i in input().split()]
su = 0
group.sort()
su += sum(group)
for j in range(n):
	if j != n - 1:
		su += group[j] * (j + 1)
	else:
		su += group[j] * j
print(su)


import math
n = int(input())
lst = list(map(int, input().strip().split(' ')))
lst.sort(reverse=True)
if n == 1:
	print(lst[0])
elif n == 2:
	print(sum(lst) * 2)
else:
	c = n - 1
	s = 0
	for i in range(n):
		if i == 0 or i == 1:
			s += n * lst[i]
		else:
			s += lst[i] * c
			c -= 1
	print(s)


n = int(input())
a = list(map(int, input().split()))
rsort_a = sorted(a, reverse=True)
an = len(a)
i = 1
ans = sum(a)
add = rsort_a[0]
while i < an:
	rsort_ai = rsort_a[i]
	ans += add + rsort_ai
	add += rsort_ai
	i += 1
print(ans)


a = int(input())
s = sorted([int(i) for i in input().split()])
total = sum([(i + 2) * j if i < len(s) - 1 else (i + 1) * j for (i, j) in enumerate(s)])
print(total)


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
n = I()
a = LI()
a.sort()
b = sum(a)
ans = b
val = 0
for i in range(n - 1):
	ans += a[i]
	val += a[i]
	ans += b - val
print(ans)


T = int(input())
lst = list(map(int, input().split()))
lst.sort()
if len(lst) <= 1:
	print(sum(lst))
elif len(lst) == 2:
	print(2 * sum(lst))
else:
	s = 0
	x = sum(lst)
	for i in range(len(lst) - 2):
		x -= lst[i]
		s += x
	s += sum(lst)
	s += sum(lst)
	print(s)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	a.sort(reverse=True)
	t1 = a[0]
	t2 = 0
	i = 1
	while i < n:
		t1 += a[i]
		t2 += t1
		i += 1
	i = 0
	while i < n:
		t2 += a[i]
		i += 1
	print(t2)


x = int(input())
a = list(map(int, input().split()))
s = sum(a)
a.sort()
if len(a) > 1:
	k = s * 2
else:
	k = s
for i in range(x - 2):
	s = s - a[i]
	k += s
print(k)


n = int(input())
In = input().split()
IN = []
for i in range(0, n):
	IN.append(int(In[i]))
IN.sort()
ans = sum(IN) - IN[n - 1]
for i in range(0, n):
	ans += IN[i] * (i + 1)
print(ans)


import math
mod = 1000000007

def power(a, b):
	res = 1
	b = b % (mod - 1)
	while b > 0:
		if b % 2 != 0:
			res = res % mod * (a % mod) % mod
		b = b // 2
		a = a % mod
		a = a * a % mod
	res = res % mod
	return res
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
s = 2 * sum(a)
for i in range(0, n - 1):
	s = s + i * a[i]
s = s + (n - 2) * a[n - 1]
print(s)


n = int(input())
a = map(int, input().split())
b = list(a)
b.sort()
s = 0
if n == 1:
	print(b[0])
else:
	for i in range(n):
		if i == n or i == n - 1:
			s += n * b[i]
		else:
			s += b[i] * (i + 2)
	print(s)


n = int(input())
list = [int(i) for i in input().split()]
list.sort()
a = 0
b = n
while n > 0:
	a = a + n * list[n - 1]
	n = n - 1
list1 = list[0:b - 1]
a = a + sum(list1)
print(a)


n = int(input())
list1 = [int(i) for i in input().split()]
list1.sort()
if n == 1:
	wox = list1[0]
elif n == 2:
	wox = 2 * (list1[0] + list1[1])
else:
	i = 2
	wox = 0
	while i < n:
		k = list1[i - 2]
		wox = i * k + wox
		i += 1
	wox = wox + (list1[n - 2] + list1[n - 1]) * n
wox = wox
print(wox)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
t = 2
ans = 0
for v in A:
	ans += t * v
	t += 1
ans -= A[-1]
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.sort()
su = l[n - 1] * n
c = n
for i in range(n - 2, -1, -1):
	su += l[i] * c
	c -= 1
print(su)


n = int(input())
a = [int(x) for x in input().split(' ')]
b = sorted(a)
ans = 0
for i in range(n):
	ans += b[i] * (i + 2)
tol = ans - b[n - 1]
print(tol)


(a, b) = (input(), sorted(map(int, input().split())))
c = 0
for i in range(len(b)):
	c += (i + 2) * b[i]
print(c - b[-1])


f1 = lambda : list(map(int, input().split()))
f2 = lambda : map(int, input().split())
n = int(input())
arr = f1()
arr = sorted(arr)
ans = sum(arr)
res = 0
for i in range(n):
	res += ans + arr[i]
	ans -= arr[i]
print(res - arr[-1])


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
q = 0
a.sort()
for i in range(n):
	q = q + (i + 2) * a[i]
q = q - a[n - 1]
print(q)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = 0
for i in range(0, n):
	s += a[i] * (i + 2)
s -= a[-1]
print(s)


n = int(input())
l = list(map(int, input().split()))
l.sort()
score = 0
for i in range(n):
	score = score + (i + 2) * l[i]
print(score - l[-1])


n = int(input())
line = [int(j) for j in input().split()]
line.sort()
m = 0
for k in range(n):
	m += (k + 2) * line[k]
print(m - line[n - 1])


n = int(input())
list_1 = input().split()
list_1 = list(map(int, list_1))
m = sum(list_1)
total = sum(list_1)
list_2 = sorted(list_1)
list_2 = list_2[::-1]
if n != 1:
	while n > 1:
		total += m
		m -= list_2[-1]
		list_2.pop()
		n -= 1
else:
	total = sum(list_1)
print(total)


n = int(input())
line = [int(i) for i in input().split()]
line = sorted(line)
score = 0
if len(line) == 1:
	score += sum(line)
elif len(line) == 2:
	score += 2 * sum(line)
else:
	for i in range(0, n - 2):
		score += (i + 2) * line[i]
	score += n * (line[-1] + line[-2])
print(score)


N = int(input())
l = list(map(int, input().split()))
s = 0
l.sort()
if N == 1:
	s = s + l[0]
else:
	for i in range(0, N):
		if i == N - 1 or i == N - 2:
			s += l[i] * N
		else:
			s += l[i] * (i + 2)
print(s)


n = int(input())
sb = list(map(int, input().split()))
sb.sort()
x = 0
total = 0
for i in range(len(sb)):
	total += (i + 2) * sb[i]
total -= sb[i]
print('{}'.format(total))


num_numbers = int(input())
numbers = list(map(int, input().split()))
numbers.sort(reverse=True)
solution = num_numbers * numbers[0]
for pos in range(1, len(numbers)):
	solution += (num_numbers + 1 - pos) * numbers[pos]
print(solution)


n = int(input())
l1 = []
l1 = input().split()
l = []
for i in l1:
	i = int(i)
	l.append(i)
l = sorted(l)
pri = 1
sum1 = 0
while pri <= n:
	num1 = int(l[pri - 1])
	sum1 += num1 * (pri + 1)
	pri += 1
sum1 = sum1 - int(max(l))
print(sum1)


n = int(input())
str1 = input()
list1 = [int(k) for k in str1.split(' ')]
list1.sort()
sum = 0
for i in range(n - 1):
	sum = sum + list1[i] * (i + 2)
sum = sum + list1[n - 1] * n
print(sum)


n = int(input())
a = sorted(tuple(map(int, input().split())))
ans = 0
for i in range(n - 1):
	ans += (i + 2) * a[i]
ans += n * a[n - 1]
print(ans)


n = int(input())
lst = [int(i) for i in input().split()]
total = 0
lst.sort()
for i in range(n):
	total += lst[i] * (i + 2)
total -= max(lst)
print(total)


n = int(input())
array = [int(i) for i in input().split()]
Score = sum(array)
array.sort()
appleMan = Score
for i in range(n - 1):
	appleMan += array[i]
	Score -= array[i]
	appleMan += Score
print(appleMan)
array.clear()


n = int(input())
a = [int(i) for i in input().split()]
s = sum(a)
j = s
s0 = 0
a.sort()
if len(a) != 1:
	for i in range(len(a) - 1):
		s += j - s0
		s0 += a[i]
print(s)


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


s = 0
n = int(input())
grp = [int(x) for x in input().split()]
grp.sort()
s += sum(grp)
for i in range(n):
	s += grp[i] * (i + 1)
s -= grp[n - 1]
print(s)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s1 = sum(l)
s2 = 0
ans = s1
for i in range(n - 1):
	s2 += l[i]
	ans += s1 + l[i] - s2
print(ans)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	n = int(input())
	arr = array()
	arr.sort()
	s = sum(arr)
	res = 0
	for i in range(n - 1):
		res += s
		s -= arr[i]
	print(res + sum(arr))
t = 1
for _ in range(t):
	main()


def count(a, n):
	a = sorted(a)
	ans = 0
	times = 1
	for i in range(n - 1):
		times += 1
		ans += times * a[i]
	ans += times * a[n - 1]
	return ans

def main():
	n = int(input())
	a = list(map(int, input().split()))
	print(count(a, n))
main()


def sum_l(lst):
	temp = 0
	for i in lst:
		temp += i
	return temp
l1 = input()
l1 = int(l1)
a = input()
l2 = [int(x) for x in a.split()]
l2.sort()
ans = 0
if len(l2) == 1:
	ans += l2[0]
else:
	n = 0
	for i in l2:
		ans += i * (n + 2)
		n += 1
	ans -= l2[-1]
print(ans)


n = int(input())
m = input().split()
for i in range(len(m)):
	m[i] = int(m[i])
l = sorted(m)
a = 0
for i in range(n - 1):
	a += int(l[i]) * (i + 2)
a += int(l[n - 1]) * n
print(a)


b = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = 0
for i in range(0, b):
	c = c + int(a[i]) * (i + 2)
c = c - int(a[b - 1])
print(c)


n = int(input())
l = list(map(int, input().split()))
l.sort()
if len(l) == 1:
	print(sum(l))
else:
	s = 2 * sum(l)
	temp = sum(l)
	for i in range(0, n - 2):
		temp = temp - l[i]
		s = s + temp
	print(s)


N = int(input())
line = input()
list = line.split(' ')
list1 = []
for i in list:
	list1.append(int(i))
list1.sort()
ans = 0
for i in range(0, N - 1):
	ans = ans + (i + 2) * list1[i]
ans = ans + N * list1[N - 1]
print(ans)


n = int(input())
line = input().split()
lists = map(int, line)
a = []
for i in lists:
	a.append(i)
t = []
for j in range(n):
	t.append(0)
b = sorted(a)
for k in range(n - 1):
	t[k] = b[k] * (k + 2)
t[n - 1] = b[n - 1] * n
num = sum(t)
print(num)


from sys import stdin
n = int(input())
arr = list(map(int, stdin.readline().rstrip().split(' ')))
arr = sorted(arr)
prefixArr = [0] * (n + 1)
for i in range(n):
	prefixArr[i + 1] += prefixArr[i] + arr[i]
answer = prefixArr[-1]
for i in range(n - 1):
	answer += prefixArr[-1] - prefixArr[i]
print(answer)


n = int(input())
A = sorted(list(map(int, input().split())))
ans = sum(A)
cnt = 1
for (i, a) in enumerate(A):
	ans += a * cnt if i != n - 1 else a * (cnt - 1)
	cnt += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
q = sorted(a)
s = 0
for i in range(n):
	s += q[i] * (i + 2)
print(s - q[n - 1])


n = int(input())
s = [int(i) for i in input().split()]
s.sort()
a = sum(s)
for i in range(n):
	a += s[i] * (i + 1)
a -= s[n - 1]
print(a)


def f():
	m = 0
	for i in s:
		m += i
	return m
n = int(input())
s = [int(i) for i in input().split()]
s.sort()
k = 0
for i in range(n):
	k += (n - i) * s[-(i + 1)]
print(k + f() - s[-1])


n = int(input())
s = 0
l = [int(i) for i in input().split()]
l.sort()
for x in range(0, len(l)):
	s += (x + 2) * l[x]
print(int(s - max(l)))


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


n = int(input())
m = [int(x) for x in input().split(' ')]
score = sum(m)
m.sort()
for i in range(len(m)):
	score += (i + 1) * m[i]
score -= max(m)
print(score)


n = int(input())
nums = input().split()
for x in range(n):
	nums[x] = int(nums[x])
nums.sort()
if n == 1 or n == 2:
	print(sum(nums) * n)
else:
	score = sum(nums) * n
	for i in range(n - 2):
		score -= nums[i] * (n - i - 2)
	print(score)


n = int(input())
num = [int(n) for n in input().split()]
score = 0
num.sort()
if len(num) != 1:
	for i in range(len(num) - 1):
		score = score + num[i] * (i + 2)
	score = score + num[n - 1] * n
if len(num) == 1:
	score = num[0]
print(score)


n = int(input())
list1 = input()
list1 = list1.split()
for i in range(n):
	list1[i] = int(list1[i])
list1.sort()
total = 0
for i in range(1, n):
	total += (i + 1) * int(list1[i - 1])
total += n * int(list1[n - 1])
print(total)


n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
score = sum(lst)
last = score
for j in range(len(lst) - 1):
	score = score + lst[j]
	temp = last - lst[j]
	score = score + temp
	last = temp
print(score)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if val % ll[mid] == 0:
			ans = ll[mid]
			return binary(l, mid - 1, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def odd(n, ans, s):
	if n % 2 != 0 or n in s:
		return ans
	else:
		s.add(n)
		return odd(n // 2, ans + 1, s)
n = int(input())
score = 0
l = list(map(int, input().split(' ')))
l.sort()
for i in range(n):
	if i == n - 1:
		score += (i + 1) * l[i]
	else:
		score += (i + 2) * l[i]
print(score)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
s = n * a[0]
for i in range(n - 1):
	s += a[i + 1] * (n - i)
print(s)


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
a = sorted(li())
if n == 1:
	print(a[0])
elif n == 2:
	print(sum(a) * 2)
else:
	ans = 0
	for i in range(n):
		ans += a[i] * (i + 2)
	print(ans - a[-1])


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
count = 0
for i in range(2, n + 1):
	count += arr[i - 2] * i
print(count + arr[-1] * n)


n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for (i, x) in enumerate(l):
	if i >= n - 2:
		cnt = cnt + x * n
	else:
		cnt = cnt + x * (i + 2)
print(cnt)


n = int(input())
ss = input()
list1 = []
list1.extend([int(i) for i in ss.split()])
sum1 = 0
list2 = []
list2.extend([int(i) for i in sorted(list1)])
for i in range(n - 1):
	sum1 += list2[i] * (i + 2)
sum1 += list2[n - 1] * n
print(sum1)


from sys import stdin
A = int(stdin.readline())
B = list(map(int, stdin.readline().split()))
K = 0
if A == 1:
	print(B[0])
	K = 1
if A == 2:
	print(2 * (B[0] + B[1]))
	K = 1
if K == 0:
	B.sort()
	sum = B[len(B) - 1] + B[len(B) - 2]
	ans = sum
	for t in range(len(B) - 3, -1, -1):
		sum += B[t]
		ans += sum
	ans += sum
	print(ans)


x = int(input())
y = [int(a) for a in input().split()]
s = sum(y)
y = sorted(y)
ss = s
for i in range(x - 1):
	ss += s
	s -= y[i]
print(ss)


n = int(input())
a = list(map(int, input().split()))
t = 0
a.sort()
for i in range(n):
	t += a[i]
l = t
a.reverse()
while a != []:
	k = a.pop()
	t = t - k
	l = l + (t + k)
print(l - k)


n = int(input())
a = [int(i) for i in input().split()]
output = 0
a.sort()
output = sum(a)
for i in range(n - 1):
	output = output + a[i] * (i + 1)
output = output + a[n - 1] * (n - 1)
print(output)


def main():
	n = int(input())
	seq = [int(c) for c in input().split()]
	if n == 1:
		print(seq[0])
		return
	seq.sort()
	s = sum(seq)
	ans = 2 * s
	for i in range(n - 2):
		s -= seq[i]
		ans += s
	print(ans)
main()


n = int(input())
lis = input().split()
for i in range(n):
	lis[i] = int(lis[i])
lis.sort()
m = max(lis)
s = 0
for i in range(len(lis)):
	s += lis[i] * (i + 2)
print(s - m)


n = int(input())
l = input().split()
score = 0
k = 0
while k < n:
	l[k] = int(l[k])
	k = k + 1
l.sort()
k = 0
while k < n:
	score += l[k] * (k + 2)
	k = k + 1
score -= max(l)
print(score)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
m = n
s = a[0] * m
for i in range(1, n):
	s += a[i] * m
	m -= 1
print(s)


from heapq import heappush, heappop
n = int(input())
v = [int(i) for i in input().split()]
ans = sum(v)
s = ans
q = []
for i in range(n):
	heappush(q, v[i])
v = None
while len(q) > 1:
	t = heappop(q)
	s -= t
	ans += t
	ans += s
print(ans)


count = 0
x = input()
num = [int(x) for x in input().split()]
num.sort()
if len(num) == 1:
	print(num[0])
	exit()
else:
	for i in range(len(num) - 2):
		count += num[i] * (i + 2)
	count += (num[-1] + num[-2]) * len(num)
print(count)


n = int(input())
a = sorted([int(i) for i in input().split()])
k = 2
score = 0
for i in a:
	score += i * k
	k += 1
print(score - a[-1])


a = int(input())
b = input().split()
c = [i for i in range(a)]
if a == 1:
	print(int(b[0]))
else:
	for i in range(a):
		c[i] = int(b[i])
	c.sort()
	Sum = 0
	for i in range(a - 2):
		Sum += (i + 2) * c[i]
	Sum += a * (c[a - 2] + c[a - 1])
	print(Sum)


n = int(input())
list = [int(k) for k in input().split()]
list.sort()
sum = 0
if n == 1:
	sum = list[0]
elif n == 2:
	sum = 2 * (list[0] + list[1])
else:
	for i in range(n - 2):
		sum += list[i] * (i + 2)
	sum += n * (list[n - 2] + list[n - 1])
print(sum)


import heapq
N = int(input())
L = list(map(lambda x: int(x) * -1, input().split()))
ans = 0
heapq.heapify(L)
while N > 1:
	t = heapq.heappop(L) + heapq.heappop(L)
	ans -= t
	heapq.heappush(L, t)
	N -= 1
print(ans - L[0])


n = int(input())
ar = [int(i) for i in input().split()]
score = 0
ar.sort()
for i in range(n - 1):
	score += ar[i] * (i + 2)
score += ar[n - 1] * n
print(score)


N = int(input())
group = list(map(int, input().split()))
group.sort()
score = 0
if N > 1:
	for i in range(N):
		score += group[i] * (i + 2)
	score -= max(group)
else:
	score += group[0]
print(score)


n = int(input())
s = list(map(lambda x: int(x), input().split(' ')))
s.sort()
sum = 0
for i in range(n - 1):
	sum += (i + 2) * s[i]
sum += n * s[n - 1]
print(sum)


n = int(input())
a = sorted(map(int, input().split()))
res = -a[-1]
for i in range(n):
	res += a[i] * (i + 2)
print(res)


n = int(input())
seq = list(map(int, input().split()))
score = 0
seq.sort()
cur_sum = sum(seq)
for i in range(n - 1):
	score += cur_sum + seq[i]
	cur_sum -= seq[i]
score += seq[n - 1]
print(score)


n = int(input())
s = [int(i) for i in input().split()]
s.sort()
total = sum(s)
r = total
for i in range(n - 2):
	if n == 1:
		break
	total += r - s[i]
	r = r - s[i]
print(total + (sum(s) if n > 1 else 0))


t = int(input())
n = list(map(int, input().split()))
if len(n) == 1:
	print(n[0])
else:
	n.sort()
	score = 0
	for i in range(t):
		score += n[i] * (i + 1)
	print(score + sum(n) - n[t - 1])


def main():
	n = int(input())
	a = sorted([int(c) for c in input().split()])
	s = sum(a)
	mn = score = i = 0
	while i < n:
		score += s + mn
		mn = a[i]
		i += 1
		s -= mn
	print(score)
main()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = n * a[-1]
for i in range(n - 1):
	ans += (i + 2) * a[i]
print(ans)


n = int(input())
Li = [int(i) for i in input().split()]
Li.sort()
S = sum(Li)
for i in range(n):
	S += (i + 1) * Li[i]
S -= Li[n - 1]
print(S)


n = int(input())
a = list(map(int, input().split()))
a.sort()
t = 0
for i in range(n):
	t += a[i] * min(i + 2, n)
print(t)


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
a = list(map(int, input().split()))
a.sort()
p = sum(a)
E = p
for i in range(n):
	E += p
	p -= a[i]
print(E - a[-1])


print(input() * 0 + str((lambda a: sum([a[i] * (i + 2) for i in range(len(a))]) - a[-1])(sorted(tuple(map(int, input().split()))))))


n = int(input())
numbers = map(int, input().split(' '))
numbers = sorted(numbers)
res = 0
index = 2
for x in numbers:
	res += index * x
	index += 1
if n > 0:
	res -= numbers[n - 1]
print(res)


import sys
n = int(input())
a = [int(i) for i in input().split(' ')]
a = sorted(a)
summa2 = 0
summa3 = 0
for i in range(n - 2):
	summa3 += a[i]
	summa2 += summa3
summa = sum(a) * n - summa2
print(summa)


n = int(input())
m = n
s = list(map(int, input().split()))
s.sort()
t = 0
for i in range(len(s)):
	t += s[i] * (i + 2)
t -= s[-1]
print(t)


n = int(input())
x = [int(i) for i in input().split()]
sum1 = 0
x.sort()
if len(x) < 2:
	sum1 = sum(x)
else:
	for i in range(len(x)):
		if i < len(x) - 1:
			sum1 += (i + 2) * x[i]
		else:
			sum1 += (i + 1) * x[i]
print(sum1)


n = int(input())
line = input().split()
line = [int(i) for i in line]
line.sort()
if n == 1:
	out = line[0]
else:
	line = [line[i] * min(n, i + 2) for i in range(n)]
	out = sum(line)
print(out)


n = int(input())
a = sorted(map(int, input().split()))
ans = 0
for (i, e) in enumerate(a, 2):
	ans += e * i
print(ans - a[-1])


n = int(input())
a = [0 for i in range(n)]
line = input()
temp = line.split()
for i in range(n):
	a[i] = int(temp[i])
if n == 1:
	print(a[0])
else:
	ans = 0
	a.sort()
	for i in range(0, n - 2):
		ans = ans + (i + 2) * a[i]
	ans += (a[n - 2] + a[n - 1]) * n
	print(ans)


from math import ceil
from math import floor

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_least_diff(n):
	A = 2 * (pow(2, n / 2 - 1) - 1)
	B = -pow(2, n / 2)
	return int(abs(B - A))

def find_ways(n):
	return (n - 1) // 2

def count_digits(n):
	m = 9
	count = n
	while True:
		if n >= m:
			count += n - m
		else:
			break
		m = str(m)
		m += '9'
		m = int(m)
	return count

def find_max_score(n, arr):
	m = n
	count = 0
	flag = True
	arr.sort()
	for i in range(0, n - 1):
		count += arr[i] * (i + 2)
	count += arr[n - 1] * n
	return count

def get_board(n, m, mat):
	for i in range(n):
		for j in range(m):
			print(i, j)
			if mat[i][j] == '.':
				if (j > 0 and mat[i][j - 1] != 'B') and (i > 0 and mat[i - 1][j] != 'B'):
					mat[i][j] = 'B'
				else:
					mat[i][j] = 'W'
	for i in range(n):
		for j in range(m):
			print(mat[i][j])
t = 1
while t:
	t = t - 1
	count = 0
	px = []
	py = []
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	print(find_max_score(n, arr))


import sys
n = int(sys.stdin.readline())
a = sys.stdin.readline()

def findMax(n, a):
	a = a.split()
	left = 0
	right = n - 1
	a = [int(x) for x in a]
	a.sort()
	s = sum(a)
	mx = 0
	for x in a:
		mx += x + s
		s -= x
	mx -= x
	return mx
print(findMax(n, a))


n = int(input())
N = [int(i) for i in input().split()]
su = 0
N.sort()
for i in range(n):
	su += i * N[i] + 2 * N[i]
su = su - N[n - 1]
print(su)


def appleman_and_toastman(n, a):
	b = sorted(a)
	s = sum(b)
	t = s
	if n > 1:
		for i in range(n - 1):
			t += b[i]
			s -= b[i]
			t += s
	return t
n = int(input())
a = list(map(int, input().split()))
print(appleman_and_toastman(n, a))


a = int(input())
b = sorted(list(map(int, input().split())))
if a == 1:
	print(b[0])
else:
	print(sum(map(lambda x: (x + 2) * b[x], range(a - 1))) + b[-1] * a)


n = int(input())
X = sorted(list(map(int, input().split())))
Sum = sum(X)
Total = Sum
Prev = 0
for i in range(n):
	Total += Sum - Prev
	Prev += X[i]
print(Total - X[-1])


n = int(input())
a = list(map(int, input().split()))
t = sum(a)
a = sorted(a)
k = t
for i in range(n - 1):
	k += t
	t -= a[i]
print(k)


n = int(input())
l = list(map(int, input().split()))
s = 0
l.sort()
l = l[::-1]
k = [0] * n
k[0] = l[0]
for i in range(1, n):
	k[i] = k[i - 1] + l[i]
s = s + k[n - 1]
s = s + sum(k) - l[0]
print(s)


n = int(input())
line = list(map(int, input().split()))
line.sort()
total = 0
for i in range(n):
	total += line[i] * (i + 2)
print('{}'.format(total - line[-1]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
score = a[n - 1] * n
for i in range(n - 1):
	score += a[i] * (i + 2)
print(score)


n = int(input())
num = list(map(int, input().split()))
sum2 = []
if n > 1:
	num2 = sorted(num)
	i = 0
	while i < n - 1:
		sum2.append(int(num2[i]) * (i + 2))
		i += 1
	sum2.append(int(num2[n - 1]) * n)
	print(sum(sum2))
else:
	print(num[0])


n = int(input())
s = input()
k = list(map(int, s.split()))
score = 0
k.sort()
for i in range(0, n):
	score = score + (i + 2) * k[i]
score -= k[-1]
print(score)


size = int(input())
mylist = list(sorted(map(int, input().split())))
if size == 1:
	print(mylist[0])
	quit()
val = 0
for i in range(size - 1):
	val = val + mylist[i] * (i + 2)
val = val + mylist[size - 1] * size
print(val)


n = int(input())
nums = list(map(int, input().split()))
nums3 = []
if n > 1:
	nums2 = sorted(nums)
	for i in range(n - 1):
		nums3.append(int(nums2[i]) * (i + 2))
	nums3.append(int(nums2[n - 1]) * n)
	print(sum(nums3))
else:
	print(nums[0])


import sys
stdin = sys.stdin
ip = lambda : int(sp())
fp = lambda : float(sp())
lp = lambda : list(map(int, stdin.readline().split()))
sp = lambda : stdin.readline().rstrip()
Yp = lambda : print('Yes')
Np = lambda : print('No')
N = ip()
A = lp()
A.sort()
S = sum(A)
ans = S
now = N
temp = 0
if N == 1:
	ans = S
else:
	while now >= 2:
		if now == 2:
			ans += S
			break
		else:
			now -= 1
			ans += S
			S -= A[temp]
			temp += 1
print(ans)


from math import *
from collections import *
from random import *
from bisect import *
import sys
input = sys.stdin.readline

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())

def inp():
	return int(input())
n = inp()
a = lis()
if n == 1:
	print(a[0])
	exit(0)
x = sum(a)
a.sort()
r = 0
for i in range(n - 1):
	r += (i + 2) * a[i]
r += n * a[-1]
print(r)


n = int(input())
ls = list(map(int, input().split(' ')))
asum = 0
ssum = 0
ls.sort()
for j in range(len(ls)):
	asum += (j + 1) * ls[j]
	ssum += ls[j]
print(asum + ssum - ls[-1])


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


n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
ans = sum(a)
for i in range(len(a) - 1):
	a[i] *= i + 1
a[n - 1] *= n - 1
ans += sum(a)
print(ans)


n = int(input())
Line = input().split()
for i in range(n):
	Line[i] = int(Line[i])
m = 0
s = Line.sort()
for i in range(n - 1):
	m = m + (i + 2) * Line[i]
m = m + n * Line[n - 1]
print(m)


n = int(input())
l1 = list(map(int, input().split()))
l1.sort()
sum1 = 0
for i in range(n):
	if i == n - 1:
		sum1 += (i + 1) * l1[n - 1]
	else:
		sum1 += (i + 2) * l1[i]
print(sum1)


number = int(input())
total = input()
total = total.split()
total = [int(i) for i in total]
total.sort()
summation = 0
for i in range(number):
	summation = summation + total[i] * (i + 2)
summation = summation - total[-1]
print(summation)


n = int(input())
s = 0
l = input()
c = l.split()
a = []
for i in c:
	a.append(int(i))
a = sorted(a)
for i in range(n):
	s += int(a[i]) * (i + 2)
s -= int(a[-1])
print(s)


n = int(input())
p = list(reversed(sorted(list(map(int, input().split())))))
a = p
for i in range(1, n):
	a[i] += a[i - 1]
s = a[-1]
for i in range(n - 1):
	s += a[n - 1 - i]
print(s)


n = int(input())
e = input()
a = [int(x) for x in e.split()]
a.sort(reverse=True)
(ans, ans1) = (sum(a), sum(a))
for i in range(len(a) - 1, 0, -1):
	ans += a[i]
	ans1 -= a[i]
	ans += ans1
print(ans)


n = int(input())
a = 0
list = [int(i) for i in input().split()]
list.sort()
a = n * sum(list)
for i in range(n - 1):
	a -= (n - 2 - i) * list[i]
print(a)


n = int(input())
l = input().split()
l.sort(key=int)
p = 0
sum = 0
while p < n:
	sum = sum + int(l[p]) * (p + 2)
	p = p + 1
sum = sum - int(l[-1])
print(sum)


n = int(input())
li = list(map(int, input().split()))
k = 2
t = 0
li = sorted(li)
for x in li:
	t = t + k * x
	k = k + 1
t = t - li[n - 1]
print(t)


n = int(input())
x = [int(i) for i in input().split()]
x.sort(reverse=True)
m = n
y = m * x[0]
for i in range(1, n):
	y += (n - i + 1) * x[i]
print(y)


N = int(input())
(*A,) = map(int, input().split())
A.sort()
Asum = sum(A)
ans = Asum
for a in A[:-1]:
	ans += Asum
	Asum -= a
print(ans)


from collections import deque

class Solver:

	def __init__(self, N, numbers):
		self.N = N
		self.numbers = deque(sorted(numbers))
		self.total = sum(numbers)

	def solve(self):
		numbers = self.numbers
		score = self.total
		if len(numbers) == 1:
			return score
		n1 = numbers.pop()
		n2 = numbers.pop()
		score += n1
		score += n2
		tmp = n1 + n2
		while len(numbers) > 0:
			x = numbers.pop()
			score += x
			score += tmp
			tmp += x
		return score
N = int(input())
numbers = list(map(int, input().split()))
s = Solver(N, numbers)
print(s.solve())


__author__ = 'Walnut'
import math
n = int(input())
l = input().split()
line = []
for i in l:
	line.append(int(i))
line.sort()
sum = int(0)
for i in range(len(line)):
	sum += int(line[i]) * (i + 2)
sum -= int(line[len(line) - 1])
print(sum)


n = int(input())
number = list(map(int, input().split()))
number.sort()
toastman = sum(number)
for i in range(len(number) - 2):
	toastman += (i + 1) * number[i]
print(toastman + (len(number) - 1) * (number[len(number) - 2] + number[len(number) - 1]))


from heapq import *

def main():
	n = int(input())
	s = [int(a) for a in map(int, input().split())]
	heapify(s)
	res = sum(s)
	ans = res
	for i in range(n - 1):
		x = heappop(s)
		res -= x
		ans += x + res
	print(ans)
main()


n = int(input())
num = input().split()
suma = 0
for i in range(n):
	num[i] = int(num[i])
	suma += num[i]
numa = sorted(num)
ans = suma
for i in range(n - 1):
	ans += suma
	suma -= numa[i]
print(ans)


n = input()
total = 0
index = 2
nr_list = sorted([int(x) for x in input().strip().split()])
for nr in nr_list:
	total += nr * index
	index += 1
total -= nr_list[-1]
print(total)


n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
	print(sum(a))
	exit()
a.sort()
zhecijiaji = sum(a)
he = zhecijiaji * 2
for i in range(n - 2):
	zhecijiaji = zhecijiaji - a[i]
	he = he + zhecijiaji
print(he)


m = int(input())
n = sorted(list(map(int, input().split())))
l = len(n)
s = 0
for i in range(l):
	s += (i + 2) * n[i]
print(s - n[-1])


ints = int(input())
array = list(map(int, input().split(' ')))
if ints == 1:
	reference = [1]
elif ints == 2:
	reference = [2, 2]
else:
	reference = list(range(2, ints))
	reference += [ints, ints]
product = 0
array.sort()
for i in range(ints):
	product += array[i] * reference[i]
print(product)


n = int(input())
a = input()
b = a.split()
ans = 0
for i in range(n):
	b[i] = int(b[i])
b.sort()
for i in range(n):
	ans = ans + (i + 2) * b[i]
print(ans - b[n - 1])


n = int(input())
number = [int(i) for i in input().split()]
number.sort()
score = sum(number)
for i in range(n - 1):
	score += number[i] * (i + 1)
score += number[n - 1] * (n - 1)
print(score)


n = int(input())
X = list(map(int, input().split()))
ans = 0
X = sorted(X)
for i in range(n - 1):
	ans += X[i] * (i + 2)
ans += X[-1] * n
print(ans)


n = int(input())
m = input()
a = 1
if n == 1:
	print(m)
elif n == 2:
	(a, b) = map(int, m.split())
	print(2 * (a + b))
else:
	line = sorted(list(map(int, m.split())))
	s = n * line[-1]
	while a < n:
		s = s + (a + 1) * int(line[a - 1])
		a = a + 1
	print(s)


number = int(input())
data = list(map(int, input().split()))
data.sort()
if len(data) == 1:
	print(data[0])
else:
	times = len(data)
	sum1 = times * data[-1]
	i = -2
	while times > 1:
		sum1 += data[i] * times
		i -= 1
		times -= 1
	print(sum1)


def summ(a):
	s = 0
	for i in range(len(a)):
		s += a[i]
	return s

def sas(a):
	if len(a) == 1:
		return summ(a)
	elif len(a) == 3:
		if a[0] > a[2]:
			k1 = a[:1]
			k2 = a[3]
		else:
			k1 = a[1:]
			k2 = a[0]
		return sas(k1) + sas(k2) + summ(a)
	elif len(a) % 2 == 0:
		k1 = a[:len(a) - 1]
		k2 = a[len(a) - 1:]
		return sas
n = int(input())
ar = [int(i) for i in input().split()]
score = 0
ar.sort()
for i in range(n - 1):
	score += ar[i] * (i + 2)
score += ar[n - 1] * n
print(score)


n = int(input())
s = input().split()
s = [int(i) for i in s]
s.sort()
total = 0
for i in range(n):
	total += s[i] * (i + 2)
total -= s[n - 1]
print(total)


n = int(input())
m = [0 for i in range(n)]
k = input()
h = k.split(sep=None, maxsplit=-1)
for i in range(n):
	m[i] = int(h[i])
m.sort(key=None, reverse=False)
result = 0
i = 0
for i in range(len(m)):
	result += m[i] * (i + 2)
result -= m[len(m) - 1]
print(result)


n = int(input())
a = [int(j) for j in input().split()]
ans = 0
if len(a) == 1:
	ans = a[0]
else:
	a = sorted(a)
	ans = ans + n * a[n - 1] + n * a[n - 2]
	for i in range(0, n - 2):
		ans = ans + a[i] * (2 + i)
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
k = l[-1]
sum = 0
for i in range(len(l)):
	sum = sum + l[i] * (i + 2)
sum = sum - k
print(sum)


n = int(input())
m = list(map(int, input().split()))
m.sort()
s = -m[n - 1]
for i in range(n):
	s += m[i] * (i + 2)
print(s)


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
nums.reverse()
s = sum(nums)
l = 0
for i in nums:
	if l == 0:
		s += i * (n - 1)
	else:
		s += i * (n - l)
	l += 1
print(s)


n = int(input())
line = input().split()
list = []
for i in range(n):
	list.append(int(line[i]))
List = sorted(list)
sum = 0
for i in range(n - 1):
	sum += (i + 2) * List[i]
sum += n * List[n - 1]
print(sum)


import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
an.sort()
result = 0
for i in range(n):
	result += (1 + i) * an[i]
	if i != n - 1:
		result += an[i]
print(result)


import sys
n = int(input())
s = input()
if n == 1:
	print(s)
	sys.exit(0)
a = s.split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
ans = 0
for i in range(n - 1):
	ans += a[i] * (i + 2)
ans += a[n - 1] * n
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = n * sum(l)
l.sort()
i = 1
s1 = 0
for j in range(n - 3, -1, -1):
	s1 += i * l[j]
	i += 1
print(s - s1)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
nums = sum(a)
score = nums
for i in range(n - 1):
	score += nums
	nums -= a[i]
print(score)


n = int(input())
nums = input().split()
nums.sort()
num = [int(i) for i in nums]
num.sort()
x = 0
for i in range(len(num)):
	x = x + num[i] * (i + 2)
x = x - num[-1]
print(x)


n = int(input())
xs = sorted(map(int, input().split()))
r = 0
for (i, x) in enumerate(xs, start=1):
	r += x * (i + 1 if i < n else i)
print(r)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
t = s * 2
for x in a:
	s = s - x
	t += s
t -= x
print(t)


a = int(input())
b = input().split()
l = []
for i in range(a):
	l.append(int(b[i]))
sm = sum(l)
score = sm
if a > 1:
	score = score + sm
l.sort()
for i in range(a - 2):
	score = score + (sm - l[i])
	sm = sm - l[i]
print(score)


n = int(input())
L = list(map(int, input().split()))
L.sort()
r = 0
for k in range(n - 1):
	r += (k + 2) * L[k]
print(r + n * L[n - 1])


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
le = len(l)
a = 0
for i in range(n):
	a += l[i] * (i + 2)
a -= l[-1]
print(a)


n = int(input())
L = input().split()
L = [int(i) for i in L]
L.sort(reverse=True)
s = 0
for i in range(1, len(L)):
	s = s + int(L[i]) * int(n - i + 1)
s = s + int(int(n) * int(L[0]))
print(s)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = 2
result = 0
for i in a:
	result = result + i * b
	b = b + 1
result = result - a[-1]
print(result)


n = int(input())
x = list(map(int, input().split()))
x.sort()
res = 0
for (s, i) in enumerate(x, 2):
	res += min(n, s) * i
print(res)


n = int(input())
list = input().split()
sum = 0
for i in range(n):
	list[i] = int(list[i])
	sum += list[i]
count = sum
list.sort()
for j in range(n - 1):
	count -= list[j]
	sum += count + list[j]
print(sum)


from collections import deque
from math import ceil, sqrt

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
n = ii()
a = li()
x = n
s = 0
a.sort()
for i in range(n):
	s += a[i]
c = 1
for i in range(n - 1):
	s += a[i] * c
	c += 1
print(s + (c - 1) * a[n - 1])


n = int(input())
k = [int(q) for q in input().split()]
k = sorted(k)
lg = len(k)
s = 0
nn = 0
if lg > 1:
	for i in range(lg - 1):
		s += (i + 2) * k[i]
		nn = i
	s += (nn + 2) * k[nn + 1]
else:
	s += k[0]
print(s)


n = int(input())
a = input().split()
l = []
for i in range(n):
	l.append(int(a[i]))
l.sort()
sum = 0
sumt = 0
for i in range(n):
	sumt += l[i]
sum = sumt
for i in range(n - 1):
	sumt -= l[i]
	sum += sumt + l[i]
print(sum)


n = int(input())
a = sorted([int(x) for x in input().split()])
score = 0
for i in range(n):
	score = score + a[i] * (i + 2)
print(score - a[-1])


n = int(input())
a = list(map(int, input().split()))
score = sum(a)
b = []
c = []
a.sort(reverse=True)
sums = sum(a[:])
while len(a) != 1:
	score += sums
	sums -= a[-1]
	del a[-1]
print(score)


import sys
input = sys.stdin.buffer.readline
import os
from math import *
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(arr[0])
else:
	ans = 2 * sum(arr)
	arr.sort()
	s = ans // 2
	i = 0
	while i < n - 2:
		ans += s - arr[i]
		s -= arr[i]
		i += 1
	print(ans)


n = int(input())
x = list(map(int, input().split()))
x.sort()
if n == 1:
	y = x[0]
else:
	y = 0
	for i in range(0, n - 1):
		y += (i + 2) * x[i]
	y += n * x[n - 1]
print(int(y))


def sum(list):
	result = 0
	for i in range(len(list)):
		result = result + a[i]
	return result
n = input()
n = int(n)
str = input()
a = [int(i) for i in str.split()]
s = sum(a)
res = 0
a.sort()
if n == 1:
	res = s
	print(res)
elif n == 2:
	res = s * 2
	print(res)
else:
	for i in range(n - 1):
		res = res + s + a[i]
		s = s - a[i]
	print(res + a[n - 1])


import itertools as itls
import operator as op

def inputarray(func=int):
	return map(func, input().split())

def diff(v, x=0):
	v = iter(v)
	while True:
		try:
			y = next(v)
			yield (y - x)
			x = y
		except StopIteration:
			return
N = int(input())
A = sorted(inputarray())
print(sum(map(op.mul, A, range(2, len(A) + 2))) - A[-1])


n = int(input())
a = sorted(list(map(int, input().split())))
ans = sum(a)
for i in range(n):
	ans += a[i] * (i + 1)
print(ans - a[n - 1])


n = int(input())
a = input().split()
b = []
s = 0
for i in range(len(a)):
	b.append(int(a[i]))
b.sort()
for i in range(len(b)):
	s = s + b[i]
for i in range(0, len(b)):
	s = s + (i + 1) * b[i]
s = s - int(b[n - 1])
print(s)


n = int(input())
a_list = [int(x) for x in input().split()]
a_list = sorted(a_list)
ans = 0
summ = 0
sum_list = []
for i in a_list[::-1]:
	summ += i
	sum_list.append(summ)
for i in range(1, len(sum_list)):
	ans += sum_list[i]
ans += sum_list[-1]
print(str(ans))


n = int(input())
a = [int(x) for x in input().split()]
mySum = sum(a)
a = list(sorted(a))
for i in range(n):
	mySum += (i + 1) * a[i]
mySum -= a[n - 1]
print(mySum)


n = int(input())
l = list(map(int, input().split()))
l.sort()
s = sum(l)
ans = s
for i in range(n - 1):
	s -= l[i]
	ans += l[i]
	ans += s
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
score = 0
for x in range(n):
	score += (x + 2) * a[x]
score -= a[n - 1]
print(score)


n = int(input())
initial = []
line = input().split()
for i in range(n):
	t = int(line[i])
	initial.append(t)
sort = []
if n == 1:
	fin = int(initial[0])
elif n == 2:
	fin = 2 * (int(initial[0]) + int(initial[1]))
else:
	fin = 0
	sort = sorted(initial)
	for i in range(n - 1):
		fin = fin + int(sort[i]) * (i + 2)
	fin = fin + int(sort[n - 1]) * n
print(fin)


_ = input()
l_i = list(map(int, input().split()))
l_i.sort()
s = sum(l_i)
t = sum(l_i)
a_s = 0
for i in range(len(l_i) - 1):
	t += s - a_s
	a_s += l_i[i]
print(t)


N = int(input())
line = input()
a = line.split()
ans = 0
for i in range(N):
	a[i] = int(a[i])
b = a.sort()
for i in range(N):
	ans = ans + (i + 2) * a[i]
ans = ans - a[N - 1]
print(ans)


from sys import stdin, setrecursionlimit
import collections
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
arr.sort(reverse=True)
ans = sum(arr)
pref = [0] * n
pref[0] = arr[0]
for i in range(1, n):
	pref[i] = arr[i] + pref[i - 1]
for i in range(n - 1, 0, -1):
	ans += pref[i]
print(ans)


from sys import stdin, stdout
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
sum = sum(arr)
arr.sort()
total = sum
for i in range(n - 1):
	total += arr[i]
	sum -= arr[i]
	total += sum
stdout.write(str(total) + '\n')


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
N = -l[n - 1]
for i in range(n):
	N = N + l[i] * (i + 2)
print(N)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = iinp()
arr = lmp()
arr.sort(reverse=True)
pre = [arr[0]]
for i in range(1, n):
	pre.append(pre[-1] + arr[i])
ans = pre[-1] + sum(pre[1:])
print(ans)


n = int(input())
data = [int(i) for i in input().split()]
data.sort()
s = 0
for i in range(n):
	if i < n - 1:
		s += (i + 2) * data[i]
	else:
		s += (i + 1) * data[i]
print(s)


import math
n = int(input())
data = list(map(int, input().split()))
sum = 0
for i in range(n):
	sum += data[i]
ans = sum
data.sort()
for i in range(n - 1):
	ans += sum
	sum -= data[i]
print(ans)


N = int(input())
numberGroup = [int(i) for i in input().split()]
numberGroup.sort()
score = 0
for i in range(N):
	score += numberGroup[i] * (i + 2)
score -= numberGroup[-1]
print(score)


n = int(input())
arr = [int(s) for s in input().split()]
arr.sort(reverse=True)
res = 0
if n == 1:
	res = arr[0]
else:
	res = n * (arr[0] + arr[1])
	i = 2
	while i < n:
		res += (n + 1 - i) * arr[i]
		i += 1
print(res)


n = int(input())
lst = sorted([int(i) for i in input().split()])
maxScore = sum(lst)
for i in range(len(lst) - 2):
	maxScore += lst[i] * (i + 1)
print(maxScore + (lst[-1] + lst[-2]) * (len(lst) - 1) if len(lst) > 1 else maxScore)


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
ans = 0
for i in range(1, n):
	ans = ans + (i + 1) * arr[i - 1]
ans = ans + n * arr[n - 1]
print(ans)


input()
l = list(map(int, input().split()))
l.sort()
i = 0
s = 0
while i < len(l) - 1:
	s += (i + 2) * l[i]
	i += 1
s += (i + 1) * l[i]
print(s)


n = int(input())
line = input()
line = [int(i) for i in line.split()]
line = sorted(line)
max = (n - 1) * line[n - 1] + sum(line)
for i in range(n - 1):
	max += (i + 1) * line[i]
if n == 1:
	max = line[0]
print(max)


n = int(input())
a = sorted(list(map(int, input().split())))
print(sum([j * (i + 2) for (i, j) in enumerate(a)]) - a[-1])


n = int(input())
a = [int(w) for w in input().split()]
sum_score = sum(a)
ans = sum_score
if n == 1:
	print(sum_score, end='\n')
else:
	a.sort(key=int)
	ans *= 2
	for i in range(len(a) - 2):
		sum_score -= a[i]
		ans += sum_score
	print(ans, end='\n')


n = int(input())
num = [int(i) for i in input().split()]
a = []
for x in range(n):
	a.append(num[x])
a.sort()
s = 0
for y in range(n - 1):
	s = s + (y + 2) * a[y]
print(s + n * a[n - 1])


n = int(input())
l = list(map(int, input().split()))
l.sort()
print(sum((i * j for (i, j) in enumerate(l, 2))) - l[-1])


n = int(input())
line = input().split()
b = [int(i) for i in line]
a = sorted(b)
total = 0
if n == 1:
	print(a[0])
if n != 1:
	for i in range(n):
		total += a[i] * (i + 2)
	total = total - a[n - 1]
	print(total)


import math
import copy
a = input()
b = [int(q) for q in input().split()]
b.sort(reverse=True)
l = len(b)
an = 0
for i in b:
	an = an + i * (l + 1)
	l = l - 1
print(an - b[0])


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = l[0] * n
mul = n
for x in l[1:]:
	ans += x * mul
	mul -= 1
print(ans)


(_, arr) = (int(input()), sorted((int(i) for i in input().split())))
ans = sum(arr)
for (n, i) in enumerate(arr, 1):
	ans += i * n
print(ans - arr[-1])


__author__ = 'Bian'
n = input()
orig = [int(x) for x in input().split()]
orig.sort()
total = 0
for i in range(len(orig)):
	total += orig[i] * (i + 2)
total -= orig[-1]
print(total)


import sys
n = int(input())
alist = sorted(list(map(int, sys.stdin.readline().split())))
s = 0
for (i, a) in enumerate(alist):
	s += (i + 2) * a
print(s - alist[-1])


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, accumulate
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def pmat2(A):
	for ele in A:
		for j in ele:
			print(j, end='')
		print()

def seive(r):
	prime = [1 for i in range(r + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(r + 1):
		if prime[i]:
			for j in range(2 * i, r + 1, i):
				prime[j] = 0
	return prime
n = int(data())
a = sorted(L())
ans = 0
sum = 0
for i in range(n):
	ans += (i + 1) * a[i]
	sum += a[i]
print(ans + sum - a[-1])
endtime = time.time()


n = int(input())
line = [int(i) for i in input().split()]
line.sort()
sum = 0
for i in range(n - 1):
	sum += (i + 2) * line[i]
sum += n * line[-1]
print(sum)


import heapq
N = int(input())
A = sorted(list(map(lambda x: -int(x), input().split())))
if N == 1:
	print(-A[0])
	exit()
score = 0
while 1:
	a = heapq.heappop(A)
	b = heapq.heappop(A)
	c = a + b
	score += c
	heapq.heappush(A, c)
	if len(A) < 2:
		break
print(-(score + A[0]))


n = int(input())
a = sorted([int(x) for x in input().split()])
(pre, cur) = ([0], 0)
for i in a:
	cur += i
	pre.append(cur)
ans = cur
for i in range(1, len(pre) - 1):
	ans += cur - pre[i - 1]
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
l = len(a)
b = [0] * l
b[0] = a[0]
for i in range(1, l):
	b[i] = b[i - 1] + a[i]
total = 0
for i in range(n - 1, 0, -1):
	total += b[i] + a[i]
total += a[0]
print(total)


n = int(input())
B = input().split()
A = []
for i in range(n):
	A.append(int(B[i]))
A.sort()
A.reverse()
a = 0
for i in range(n - 1):
	a += A[i + 1] * (n - i)
a += A[0] * n
print(a)


n = int(input())
arr = list(map(int, input().split()))
(ans, cursum) = (0, 0)
arr.sort()
for i in range(n):
	cursum += arr[i]
for i in range(n):
	ans += cursum
	if i < n - 1:
		ans += arr[i]
	cursum -= arr[i]
print(ans)


n = int(input())
b = input().split()
x = 0
a = sorted(b, key=lambda a: int(a))
for i in range(n):
	x = x + int(a[i]) * (i + 2)
x = x - int(a[n - 1])
print(x)


n = int(input())
a = [int(k) for k in input().split()]
a = sorted(a, reverse=True)
summ = a[0] * n
for i in range(1, n):
	summ += a[i] * (n + 1 - i)
print(summ)


from sys import *
from math import *

def main():
	n = int(input())
	a = list(map(int, input().split()))
	t = n
	a = sorted(a, reverse=True)
	s = sum(a)
	ans = sum(a)
	head = a[0]
	while a != []:
		ans += a[-1]
		s -= a[-1]
		ans += s
		a.pop()
	print(ans - head)
main()


n = int(input())
a = list(map(int, input().split()))
score = 0
if n == 1:
	print(a[0])
else:
	a.sort()
	s = []
	for (i, j) in zip(range(n - 1, 0, -1), range(n - 1)):
		if i == n - 1:
			s.append(a[i] + a[i - 1])
		else:
			s.append(a[i - 1] + s[j - 1])
		if j == n - 2:
			score += s[j] * 2
		else:
			score += s[j]
	print(score)


N = int(input())
m = list(enumerate(sorted(list(map(int, input().split())))))
m[-1] = (m[-1][0] - 1, m[-1][1])
print(sum([(v[0] + 2) * v[1] for v in m]))


n = int(input())
ar = list(map(int, input().split()))
ar.sort()
s = 0
su = sum(ar)
for x in range(n):
	s += ar[x]
	s += su
	su -= ar[x]
print(s - ar[n - 1])


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	n = nmbr()
	a = sorted(lst())
	ans = 0
	for i in range(n):
		ans += (i + 1) * a[i]
	ans += sum(a)
	print(ans - a[-1])


from sys import stdin
from heapq import heappush, heappop

def main():
	inp = stdin
	numero = inp.readline()
	while numero != '':
		numero = int(numero.strip())
		juego = inp.readline().strip().split()
		print(solucion(juego))
		numero = inp.readline()

def solucion(Arreglo):
	juego = []
	for i in range(len(Arreglo)):
		heappush(juego, int(Arreglo[i]))
	total = sum(juego)
	contador = 0
	while juego:
		contador += total
		ultimo = heappop(juego)
		contador += ultimo
		total -= ultimo
	contador -= ultimo
	return contador
main()


n = int(input())
G = sorted(map(int, input().split()))
s = sum(G)
S = 0
for g in G:
	S += s
	s -= g
	if s:
		S += g
print(S)


n = int(input())
line = list(map(int, input().split()))
line.sort()
s = sum(line[:-1])
for i in range(n):
	s += line[i] * (i + 1)
print(s)


n = int(input())
li = list()
line = input()
lines = line.split()
for i in range(n):
	a = int(lines[i])
	li.append(a)
li.sort()
if n == 1:
	print(li[0])
if n == 2:
	print(2 * (li[0] + li[1]))
if n >= 3:
	t = 0
	for i in range(n - 2):
		t = t + (i + 2) * li[i]
	t += n * li[n - 2]
	t += n * li[n - 1]
	print(t)


n = int(input())
numbers = input().split()
numbers = [int(i) for i in numbers]
numbers.sort()
if n == 1:
	total = numbers[0]
else:
	total = 0
	for i in range(n - 1):
		total += numbers[i] * (i + 2)
	total += numbers[-1] * n
print(total)


import sys
from heapq import heappop, heappush, heapify

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return map(int, sys.stdin.readline().rstrip().split())

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

def LI2():
	return list(map(int, sys.stdin.readline().rstrip()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def LS2():
	return list(sys.stdin.readline().rstrip())
n = I()
A = LI()
X = [-a for a in A]
heapify(X)
ans = 0
while len(X) >= 2:
	a = heappop(X)
	b = heappop(X)
	ans -= a + b
	heappush(X, a + b)
ans -= X[0]
print(ans)


a = int(input())
b = input().split()
for i in range(0, len(b)):
	b[i] = int(b[i])
b = sorted(b)
i = 0
x = 2
s = 0
while i <= a - 1:
	s = s + int(b[i]) * x
	i = i + 1
	x = x + 1
s = s - int(b[-1])
print(s)


n = int(input())
a = input().split()
m = 0
for i in range(n):
	a[i] = int(a[i])
a = sorted(a)
m = sum(a)
if n > 1:
	for i in range(n):
		m += (i + 1) * a[i]
	m -= a[-1]
print(m)


n = int(input())
if n == 1:
	print(input())
else:
	group = input().split()
	group = [int(i) for i in group]
	group.sort(reverse=True)
	if n >= 3:
		score = n * (group[0] + group[1])
		for i in range(2, n):
			score += (n + 1 - i) * group[i]
	elif n == 2:
		score = 2 * sum(group)
	print(score)


import heapq
n = int(input())
a = list(map(int, input().split()))
heapq.heapify(a)
ans = 0
sum_a = sum(a)
while a:
	ans += sum_a
	if n > 1:
		b = heapq.heappop(a)
		n -= 1
		ans += b
	else:
		break
	sum_a -= b
print(ans)


import sys, heapq
input = sys.stdin.readline

def main():
	N = int(input())
	q = []
	for a in list(map(int, input().split())):
		heapq.heappush(q, a)
	sum_ = sum(q)
	tmp = 0
	ans = sum_
	while len(q) > 1:
		tmp = heapq.heappop(q)
		ans += sum_
		sum_ -= tmp
	print(ans)
main()


n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
s = 0
b = sum(a)
temp = 0
for i in range(n):
	temp += a[i]
	a[i] = temp
	s += a[i]
print(s + b - a[0])


n = int(input())
a = list((int(x) for x in input().split()))
a.sort(reverse=True)
s = a[0] * n
for i in range(1, n):
	s = s + a[i] * (n - i + 1)
print(s)


n = int(input())
nlist = [int(i) for i in input().split()]
nlist = sorted(nlist)
score = 0
for i in range(n):
	score += nlist[i] * (i + 2)
print(score - nlist[-1])


n = int(input())
ls = list(map(int, input().split()))
ls.sort(reverse=True)
product = list(range(n + 1, 1, -1))
product[0] -= 1
ans = 0
for i in range(n):
	ans += ls[i] * product[i]
print(ans)


input()
l = list(map(int, input().split()))
s = 0
l.sort()
for i in range(len(l)):
	s += l[i] * (i + 2)
s -= l[-1]
print(s)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
	else:
		a.sort()
		s = -a[-1]
		for i in range(n):
			s += a[i] * (i + 2)
		print(s)
main()


n = input()
l = sorted(map(int, input().split()))
print(sum([x * (i + 2) for (i, x) in enumerate(l)]) - l[-1])


__author__ = 'Utena'
n = int(input())
s = sorted(list(map(int, input().split())))
t = 0
for i in range(n):
	t += s[i] * (i + 2)
print(t - s[-1])


n = int(input())
lista = [int(i) for i in input().split()]
lista.sort()
cnt = -lista[-1]
for i in range(0, n):
	cnt += lista[i] * (i + 2)
print(cnt)


n = int(input())
a = sorted(map(int, input().split()), reverse=True)
for i in range(1, n):
	a[i] += a[i - 1]
s = a[-1]
for i in range(1, n):
	s += a[n - i]
print(s)


n = int(input())
line = input().split()
so = []
s = 0
for i in range(n):
	x = int(line[i])
	so.append(x)
sort = so.sort()
for i in range(n):
	s = s + (i + 2) * so[i]
s = s - so[n - 1]
print(s)


n = int(input())
group = sorted(list(map(int, input().split(' '))))
score = sum(group)
for i in range(n - 1):
	score += group[i] * (i + 1)
score += group[n - 1] * (n - 1)
print(score)


def main():
	n = int(input())
	numbers = list(map(int, input().split()))
	numbers = sorted(numbers, reverse=True)
	ans = 0
	for (i, num) in enumerate(numbers):
		if i == 0:
			ans += num * n
		else:
			ans += num * (n - i + 1)
	print(ans)
main()


n = int(input())
s = input().split()
s = list(map(int, s))
s.sort()
total = 0
for i in range(n):
	if n - 1 == i:
		total = s[i] * (i + 1) + total
	else:
		total = total + s[i] * (i + 2)
print(total)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
p = sum(a)
for i in range(n - 1):
	t = a[i] * (i + 1)
	p += t
p += a[n - 1] * (n - 1)
print(p)


n = input()
a = [int(i) for i in input().split()]
a.sort()
score = 0
for i in range(len(a)):
	score += (i + 2) * a[i]
score -= a[len(a) - 1]
print(score)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
a = [nextInt() for i in range(n)]
a.sort()
s = sum(a)
res = s * 2
for i in a:
	s -= i
	res += s
res -= a[-1]
print(res)


n = int(input())
line = input()
line_new = [int(i) for i in line.split()]
line_new.sort()
value = 0
length = len(line_new)
i = length
if i <= 1:
	value = line_new[0]
	print(value)
else:
	value = value + line_new[-1] * i + line_new[-2] * i
	i = i - 1
	while i >= 2:
		value = value + line_new[i - 2] * i
		i = i - 1
	print(value)


s = 0
t = 2
(n, a) = (int(input()), list(map(int, input().split())))
if n == 1:
	print(a[0])
else:
	a = sorted(a)
	for i in range(n - 2):
		s += t * a[i]
		t = t + 1
	s += t * (a[n - 2] + a[n - 1])
	print(s)


n = int(input())
data = list(map(int, input().split()))
data.sort()
ans = 0
for (i, x) in enumerate(data, 2):
	ans += x * i
ans -= data[-1]
print(ans)


n = int(input())
x = input()
x += ' '
num = ''
nums = []
score = 0
for letter in x:
	if letter != ' ':
		num += letter
	else:
		nums.append(int(num))
		num = ''
nums.sort(reverse=True)
score += n * nums[0]
nums.remove(nums[0])
for i in range(n - 1):
	g = (n - i) * nums[i]
	score += g
print(score)


n = int(input())
s = [int(i) for i in input().split()]
s = sorted(s)
a = 0
for i in s:
	a += i
k = 2 * a
i = 0
if n <= 2:
	print(n * a)
else:
	while i < n - 2:
		a -= int(s[i])
		k += a
		i += 1
	print(k)


n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
s = 0
for i in range(n):
	s += (i + 2) * a[i]
print(s - a[n - 1])


n = input()
a = sorted(list(map(int, input().split())))
s = 0
S = 0
for (i, k) in enumerate(a):
	s += k * (i + 1)
	S += k
print(s - k + S)


def solve():
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	a.sort()
	if n == 1:
		return a[0]
	else:
		m = [i + 2 for i in range(n)]
		m[-1] -= 1
		return sum([x * y for (x, y) in zip(a, m)])
print(solve())


n = int(input())
i = 0
sum = 0
m = 0
L = input()
L = L.split()
L.sort()
L.sort(key=lambda x: len(x))
for i in range(n):
	m += int(L[i])
for i in range(n - 1):
	m += int(L[i]) * (i + 1)
m += int(L[n - 1]) * (n - 1)
print(m)


from sys import *
from collections import Counter
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
arr.sort(reverse=True)
tot = sum(arr)
ct = n - 1
for i in range(n):
	if i < 2:
		tot += arr[i] * ct
	else:
		ct -= 1
		tot += arr[i] * ct
print(tot)


num_nums = int(input())
nums = [int(x) for x in input().split()]
nums.sort()
total = 0
for x in range(2, num_nums + 1):
	total += x * nums[x - 2]
total += num_nums * nums[-1]
print(total)


n = int(input())
lst = [int(k) for k in input().split()]
lst.sort()
lst1 = [lst[i] * (i + 2) for i in range(n)]
print(sum(lst1) - lst[-1])


def solve(xs):
	xs.sort()
	result = 0
	for (i, x) in enumerate(xs, 2):
		result += i * x
	result -= xs[-1]
	return result

def main():
	n = int(input())
	xs = [int(i) for i in input().strip().split()]
	assert len(xs) == n
	result = solve(xs)
	print(result)
main()


N = int(input())
ints = list(map(int, input().split()))
ints = sorted(ints)
cum_sum = [0] * (N + 1)
for i in range(N):
	cum_sum[i + 1] = cum_sum[i] + ints[i]
res = sum(ints)
for i in range(1, N):
	res += ints[i - 1] + (cum_sum[-1] - cum_sum[i])
print(res)


n = int(input())
a = list(map(int, input().split()))
ans = 0
if n == 1:
	print(a[0])
	exit()
a.sort()
s = sum(a)
ans += 2 * s
for i in range(n - 2):
	ans += s - a[i]
	s -= a[i]
print(ans)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
if n == 1:
	print(arr[0])
else:
	arr.sort(reverse=True)
	ans = 0
	s = sum(arr)
	ans += s
	while len(arr) > 2:
		ans += s
		s -= arr[-1]
		arr.pop(-1)
	ans += sum(arr)
	print(ans)


N = int(input())
X = input().split(' ')
Y = []
n = 0
while n < N:
	Y.append(int(X[n]))
	n = n + 1
if N == 1:
	print(X[0])
if N > 1:
	Y.sort()
	Y.reverse()
	Sum = 0
	Sum = int(Y[0]) * N + int(Y[1]) * N
	i = 2
	while i <= N - 1:
		Sum = Sum + int(Y[i]) * (N - i + 1)
		i = i + 1
	print(Sum)


n = input()
n = int(n)
group = input().split()
group = [int(group[i]) for i in range(len(group))]
group.sort()
group1 = [int(group[i]) * (i + 2) for i in range(len(group) - 1)]
print(sum(group1) + group[-1] * len(group))


n = int(input())
a = sorted([int(i) for i in input().split()])
last = sum(a)
value = 0
for i in range(0, n):
	if i == n - 1:
		value += last
	else:
		value += last + a[i]
	last = last - a[i]
print(value)


a = int(input())
b = sorted((int(i) for i in input().split()))
m = sum(b)
for i in range(a):
	m += b[i] * (i + 1)
m -= b[a - 1]
print(m)


n = int(input())
arr = [int(i) for i in input().split(' ')]
arr.insert(0, 0)
arr.sort()
for i in range(n - 1, -1, -1):
	arr[i] += arr[i + 1]
print(sum(arr) - arr[-1])


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
sumsum = sum(a)
ans = sumsum
for i in a:
	ans += sumsum
	sumsum -= i
print(ans - a[-1])


n = int(input())
L = input()
L = L.split()
for j in range(n):
	L[j] = int(L[j])
L.sort(reverse=True)
total = 0
if n == 1:
	total = L[0]
else:
	total = total + n * int(L[0])
	for i in range(1, n):
		total = total + (n + 1 - i) * int(L[i])
print(total)


times = int(input())
nums = [int(num) for num in input().split()]
sort = sorted(nums)
score = 0
for i in range(1, times):
	t = (i + 1) * sort[i - 1]
	score += t
score += sort[-1] * times
print(score)


def sum(temp):
	total = 0
	for i in temp:
		total += i
	return total
turn = int(input())
group = [int(i) for i in input().split()]
group.sort()
total = sum(group)
answer = 0
poped = 0
delete = 0
for i in range(turn):
	answer += total - delete + poped
	delete += group[i]
	poped = group[i]
print(answer)


x = int(input())
s = [int(n) for n in input().split()]
s.sort()
m = 0
for n in range(len(s)):
	m += s[n] * (n + 2)
m -= s[len(s) - 1]
print(m)


n = int(input())
a = [0] * (n + 1)
a[1:] = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(1, n + 1):
	ans += a[i] * (i + 1)
ans -= a[n]
print(ans)


from heapq import heappop, heappush, heapify
N = int(input())
L = list(map(int, input().split()))
ans = sum(L)
s = ans
heapify(L)
while len(L) > 1:
	t = heappop(L)
	s -= t
	ans += t
	ans += s
print(ans)


n = int(input())
seq = list(sorted(map(int, input().split(' '))))
if n == 1:
	print(seq[0])
else:
	ans = 0
	for i in range(n - 1):
		ans += seq[i] * (i + 2)
	ans += seq[n - 1] * n
	print(ans)


N = int(input())
if N > 2:
	n = input().split()
	l = 0
	p = 0
	j = 0
	n = sorted(n, key=lambda n: int(n))
	for i in range(N):
		l = l + int(n[i])
	for o in range(0, N - 2):
		p = int(n[o]) + p
		s = l - p
		j = j + s
	print(j + 2 * l)
if N <= 2:
	n = input().split()
	l = 0
	for i in range(N):
		l = l + int(n[i])
	print(l * N)


n = int(input())
x = list(map(int, input().split()))
x.sort()
ans = 0
total_sum = sum(x)
for i in range(n):
	ans += total_sum
	total_sum -= x[i]
	if i != n - 1:
		ans += x[i]
print(ans)


a = int(input())
b = [int(x) for x in input().split()]
b.sort()
su = 0
for k in range(0, a - 1):
	su = su + b[k] * (k + 2)
su = su + a * b[a - 1]
print(su)


n = int(input())
seq = list(map(int, input().split()))
start = 0
end = n - 1
score = 0
seq.sort(reverse=True)
if n == 1:
	print(seq[0])
else:
	tot = [seq[0]]
	for i in range(1, n):
		tot.append(seq[i] + tot[i - 1])
	score = tot[-1]
	while start != end:
		mid = end - 1
		score += tot[mid]
		score += seq[mid + 1]
		end = mid
	print(score)


N = int(input())
P = sorted(list(map(int, input().split())))
acm_P = [0 for _ in range(N)]
for i in range(N - 1, -1, -1):
	if i == N - 1:
		acm_P[i] = P[i]
	else:
		acm_P[i] = acm_P[i + 1] + P[i]
ans = sum(P)
for i in range(N - 1):
	ans += P[i]
	ans += acm_P[i + 1]
print(ans)


n = int(input())
value = [int(i) for i in input().split()]
sum = 0
value = sorted(value)
for i in range(n):
	sum += value[i] * (i + 2)
print(sum - value[n - 1])


n = int(input())
pieces = input().split()
group = []
for i in range(n):
	group.append(int(pieces[i]))
if n == 1:
	print(sum(group))
else:
	group.sort()
	score = 0
	for i in range(n - 1):
		score += group[i] * (i + 2)
	score += group[n - 1] * n
	print(score)


Inpt = int(input())
Mainlist = sorted(list(map(int, input().split(' '))))
Score = 0
if Inpt == 1:
	print(int(Mainlist[0]))
elif Inpt == 2:
	print(2 * (int(Mainlist[1]) + int(Mainlist[0])))
else:
	for i in range(len(Mainlist)):
		Score += (i + 2) * int(Mainlist[i])
	Score -= int(Mainlist[Inpt - 1])
	print(Score)


inp = input()
ar = list(map(int, input().split()))
ar.sort()
sum = 0
for el in ar:
	sum += el
final_sum = 0
for i in range(0, len(ar) - 1):
	final_sum += sum + ar[i]
	sum -= ar[i]
final_sum += sum
print(final_sum)


n = int(input())
line = input()
pieces = line.split()
li = list(map(int, pieces))
li.sort()
s = 0
for i in range(n):
	s += li[i] * (i + 2)
print(s - li[n - 1])


n = int(input())
value = []
set = [int(x) for x in input().split()]
maxElement = max(set)
sumSet = sum(set)
total = sumSet
for i in range(0, maxElement + 1):
	value.append(0)
for i in range(0, n):
	value[set[i]] += 1
for i in range(0, maxElement + 1):
	while value[i] != 0:
		total += sumSet
		sumSet -= i
		value[i] -= 1
print(total - maxElement)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter
n = int(input())
ls = list(map(int, input().split()))
ans = 0
ls.sort()
for i in range(n):
	if i == n - 1:
		ans += n * ls[i]
	else:
		ans += (i + 2) * ls[i]
print(ans)


n = int(input())
l = sorted(list(map(int, input().split())))
print(sum([l[x] * min(x + 2, n) for x in range(n)]))


n = int(input())
c = [int(x) for x in input().split(' ')]
c.sort()
d = []
f = 0
for i in reversed(c):
	f += i
	d.append(f)
print(sum(d) + d[-1] - d[0])


n = int(input())
sta = [int(j) for j in input().split()]
sta.sort()
m = len(sta)
total = sum(sta) * m
if m <= 2:
	print(total)
else:
	for i in range(m - 2):
		total -= sta[i] * (m - 2 - i)
	print(total)


n = int(input())
nums = [int(x) for x in input().split()]
nums.sort(reverse=True)
total = sum(nums)
now = 0
ans = total * n
for i in range(n - 1, 1, -1):
	num = nums[i]
	now += num
	ans -= now
print(ans)


n = int(input())
p = [int(i) for i in input().split()]
s = 0
q = sorted(p)
for i in range(len(p)):
	s += (i + 2) * q[i]
print(s - q[-1])


input()
a = list(map(int, input().split(' ')))
sum = 0
a.sort()
for i in range(len(a)):
	sum += (i + 2) * a[i]
sum -= max(a)
print(sum)


n = int(input())
l = list(map(int, input().split()))
l.sort()
if n == 1:
	print(sum(l))
else:
	c = 0
	for i in range(n - 1):
		c += l[i] * (i + 2)
	c += l[-1] * n
	print(c)


n = int(input())
l = sorted(list(map(int, input().split())))
s = [l[i] * (i + 2) for i in range(n)]
print(sum(s) - l[-1])


n = int(input())
input_list = input().split()
num = []
cur = 0
for i in range(n):
	num.append(int(input_list[i]))
	cur += num[i]
num = sorted(num, reverse=False)
ans = cur
for i in range(n - 1):
	ans = ans + cur
	cur = cur - num[i]
print(ans)


final = 0
LST = list()
n = int(input())
x = input()
y = x.split()
for i in range(n):
	LST.append(int(y[i]))
LST.sort()
for i in range(n - 1):
	final += LST[i] * (i + 2)
final += LST[n - 1] * n
print(final)


n = int(input())
l = [int(k) for k in input().split(' ')]
l = sorted(l)
s = 0
if n == 1 or n == 2:
	print(sum(l) * n)
else:
	for k in range(2, n + 2):
		s += l[k - 2] * k
	print(s - l[n - 1])


import sys
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split()]
a.sort()
score = a[-1] * n
for i in range(n - 2, -1, -1):
	score += a[i] * n
	n -= 1
print(score)


read = lambda : map(int, input().split())
n = int(input())
a = sorted(read())
ans = cur = sum(a)
for i in range(n - 1):
	ans += cur
	cur -= a[i]
print(ans)


n = int(input())
l = sorted((int(x) for x in input().split()))
s = 0
c = 1
for x in range(n - 1):
	c += 1
	s += l[x] * c
s += l[-1] * c
print(s)


n = int(input())
l = [int(i) for i in input().split()]
score = sum(l)
lsort = sorted(l)
for i in range(n):
	score += (i + 1) * lsort[i]
print(score - lsort[n - 1])


n = int(input())
lists = [int(i) for i in input().split()]
lists = sorted(lists)
total = 0
for k in range(0, n):
	total = total + (k + 1) * lists[k]
for i in range(0, n - 1):
	total = total + lists[i]
print(total)


import sys
sys.setrecursionlimit(1000 * 1000)
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
sc = 0
if n == 1:
	sc = l[0]
elif n == 2:
	sc = 2 * (l[0] + l[1])
else:
	m = 2
	for i in range(n - 1):
		sc += m * l[i]
		m += 1
	sc += n * l[n - 1]
print(sc)


import itertools
input()
a = list(map(int, str.split(input())))
a.sort(reverse=True)
print(sum(itertools.accumulate(a)) + sum(a) - max(a))


n = int(input())
nums = sorted(list(map(int, input().split())))
ans = sum(nums)
mult = 1
if n == 1:
	print(nums[0])
else:
	for i in range(n):
		if i == n - 2:
			ans += nums[n - 1] * mult
			ans += nums[n - 2] * mult
			break
		ans += nums[i] * mult
		mult += 1
	print(ans)


n = int(input())
a = list(input().split())
for i in range(0, n):
	a[i] = int(a[i])
ma = max(a)
mi = min(a)
b = (ma - mi + 1) * [0]
for i in range(0, n):
	b[a[i] - mi] += 1
c = []
for i in range(0, ma - mi + 1):
	if b[i] > 0:
		for j in range(0, b[i]):
			c += [i + mi]
s = c[n - 1] * n
for i in range(0, n - 1):
	s += c[i] * (i + 2)
print(s)


n = int(input())
x = input().split()
x = [int(y) for y in x]
x.sort()
score = 0
for i in range(len(x)):
	if i != len(x) - 1:
		score = score + x[i] * (i + 2)
	else:
		score = score + x[i] * (i + 1)
print(score)


n = int(input())
x = [int(i) for i in input().split()]
m = 0
x.sort()
for i in range(n):
	m = m + int(x[i]) * (i + 1)
m = m - int(x[n - 1]) + sum(x)
print(m)


n = int(input())
numbers = map(int, input().split(' '))
numbers = sorted(numbers, key=None, reverse=True)
sums = []
ant = 0
for x in numbers:
	ant += x
	sums.append(ant)
res = 0
tam = 0
for (x1, x2) in zip(numbers, sums):
	if tam >= 2:
		res += x1 + x2
	elif tam == 1:
		res += sums[1] * 2
	tam += 1
if n == 1:
	res += sums[0]
print(res)


N = int(input())
ls = input().split()
ls1 = []
for i in ls:
	ls1.append(int(i))
sm = 0
ls1 = sorted(ls1)
for i in range(len(ls1)):
	if i != len(ls1) - 1:
		sm += ls1[i] * (2 + i)
	else:
		sm += ls1[i] * (1 + i)
print(sm)


input()
t = list(map(int, input().split()))
t.sort()
print(sum((i * x for (i, x) in enumerate(t, 2))) - t[-1])


N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 1:
	print(A[0])
	exit()
ans = 0
for i in range(N):
	ans += A[i] * min(i + 2, N)
print(ans)


num = int(input())
line = input().split()
ls1 = []
for i in line:
	ls1.append(int(i))
s = 0
ls1 = sorted(ls1)
for i in range(len(ls1)):
	if i != len(ls1) - 1:
		s += ls1[i] * (2 + i)
	else:
		s += ls1[i] * (1 + i)
print(s)


n = int(input())
list = [int(i) for i in input().split()]
list.sort()
summ = sum(list)
for i in range(n):
	summ += list[i] * (i + 1)
summ -= list[n - 1]
print(summ)


n = int(input())
sum = 0
l = sorted(map(int, input().split()))
for j in range(n):
	sum = sum + l[j] * (j + 2)
sum -= l[-1]
print(sum)


n = int(input())
list1 = [int(i) for i in input().split()]
list1.sort()
a = sum(list1)
if len(list1) == 1:
	answer = sum(list1)
elif len(list1) == 2:
	answer = 2 * sum(list1)
else:
	answer = 0
	for i in range(len(list1) - 1):
		answer += list1[i] * (i + 2)
	answer += list1[-1] * n
print(answer)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(n,) = mp()
a = sorted(mp(), reverse=True)
score = a[0] * n
for i in range(1, n):
	score += a[i] * (n - i + 1)
cout(str(score))


n = int(input())
lis = list(map(int, input().split()))
lis.sort()
s = sum(lis)
temp = s
for i in range(n - 1):
	s = s + lis[i]
	temp = temp - lis[i]
	s = s + temp
print(s)


import sys

def main():
	fin = sys.stdin
	fout = sys.stdout
	n = int(fin.readline())
	A = list(map(int, fin.readline().split()))
	A.sort(reverse=True)
	for i in range(1, n):
		A[i] += A[i - 1]
	ans = A[n - 1]
	for i in range(1, n):
		ans += A[i]
	fout.write(str(ans) + '\n')
	fin.close()
	fout.close()
main()


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
s = sum(a)
ans = 0
for i in range(n):
	dlt = a.pop()
	ans += dlt + s
	s -= dlt
stdout.write(str(ans - dlt))


n = int(input())
days = list(map(int, input().split()))
days.sort(reverse=True)
sum = days[0] * n
for i in range(1, len(days)):
	sum += days[i] * n
	n -= 1
print(sum)


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	a.sort()
	if len(a) == 1:
		print(a[0])
	else:
		a[-2] += a[-1]
		a.pop()
		result = 0
		for i in range(n - 1):
			result += a[i] * (i + 2)
		print(result)
main()


n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
res = 0
for i in range(n):
	res += min(i + 2, n) * l[i]
print(res)


n = int(input())
a = [int(i) for i in input().split()]
he = sum(a)
suma = sum(a)
e = 0
a.sort()
while e < n - 1:
	he = he + suma
	suma -= a[e]
	e = e + 1
print(he)


n = input()
s = input().split(' ')
a = []
for c in s:
	a.append(int(c))
a = sorted(a)
ans = 0
for i in range(0, len(a) - 1):
	ans += (i + 2) * a[i]
print('%d' % (ans + len(a) * a[len(a) - 1]))


import sys
import math
n = int(sys.stdin.readline())
in_str = [int(x) for x in sys.stdin.readline().split()]
in_str.sort(reverse=True)
result = int(math.fsum(in_str))
k = result
mv = len(in_str) - 1
while mv > 0:
	result += in_str[mv]
	k = int(k - in_str[mv])
	result += k
	mv -= 1
print(result)


t = int(input())
a = list(map(int, input().split()))
if t < 2:
	print(a[0])
else:
	a.append(0)
	a.sort()
	s = sum(a)
	t = s
	i = 0
	while i < len(a) - 2:
		t = t - a[i]
		s += t
		i += 1
	print(s)


n = int(input())
line = input()
list1 = [int(i) for i in line.split()]
number = len(list1)
s = 0
list1.sort()
for i in range(number):
	if i != len(list1) - 1:
		s += list1[i] * (2 + i)
	else:
		s += list1[i] * (1 + i)
print(s)


n = int(input())
line = [int(i) for i in input().split()]
line.sort()
score = 0
for k in range(n):
	if k < n - 1:
		score += (k + 1) * line[k]
	if k == n - 1:
		score += k * line[k]
scores = sum(line) + score
print(scores)


n = int(input())
list1 = [int(i) for i in input().split()]
m = 0
if n == 1:
	print(list1[0])
elif n == 2:
	print(sum(list1) * 2)
else:
	list1.sort()
	list1.reverse()
	for i in range(0, n, 1):
		m = m + list1[i] * (n - i + 1)
	print(m - list1[0])


x = int(input())
s = input().split()
for i in range(x):
	s[i] = int(s[i])
s.sort()
sum = x * int(s[x - 1])
for i in range(x - 1):
	sum = sum + int(s[i]) * (i + 2)
print(sum)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = sorted(int_array(), reverse=True)
ans = sum(a)
sumo = ans
while len(a) > 1:
	x = a.pop()
	ans += x
	sumo -= x
	ans += sumo
print(ans)


n = int(input())
Group = list(map(int, input().split()))
Group.sort()
tmp = 0
for i in range(n):
	tmp += Group[i]
ans = tmp
for i in range(n - 1):
	ans += tmp
	tmp -= Group[i]
print(ans)


from sys import stdin

def main():
	stdin.readline()
	l = sorted(list(map(int, stdin.readline().strip().split())))
	tot = delta = sum(l)
	for x in l:
		tot += delta
		delta -= x
	return tot - x
print(main())


__author__ = 'user'
import io
import math
y = int(input())
n = y
e = list(map(int, input().split()))
f = sum(e)
g = f
e.sort()
while y > 1:
	g += f
	f -= e[n - y]
	y -= 1
print(g)


a = int(input())
b = [int(i) for i in input().split()]
b.sort()
ans = 0
for i in range(a):
	ans += int(b[i]) * (i + 2)
ans -= int(max(b))
print(ans)


import sys, math, itertools, heapq, collections, bisect, string
input = lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10 ** 9 + 7
ans = inf
count = 0
pro = 1
n = int(input())
A = sorted(map(int, input().split()))
if n == 1:
	print(A[0])
	exit()
for i in range(n - 1):
	count += A[i] * (i + 2)
count += A[-1] * n
print(count)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr1 = list(arr)
for i in range(1, len(arr)):
	arr[i] = arr[i] + arr[i - 1]
ans = arr[len(arr) - 1]
for i in range(len(arr) - 1):
	ans += arr[len(arr) - 1] - arr[i]
for i in range(0, len(arr1) - 1):
	ans += arr1[i]
print(ans)


n = int(input())
l = sorted(list(map(int, input().split())))
s = sum(l)
ans = s
for i in l[:-1]:
	ans += s
	s -= i
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
sums = sum(arr)
ans = 0
while len(arr) > 1:
	ans += sums
	x = arr.pop()
	ans += x
	sums -= x
print(ans + arr[0])


n = int(input())
ar = list(map(int, input().split()))
ans = [0] * n
ar.sort(reverse=True)
ans[0] = ar[0]
for i in range(1, n):
	ans[i] = ar[i] + ans[i - 1]
print(ans[n - 1] + sum(ans[1:]))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if n == 1:
	print(a[0])
else:
	j = 2
	sm = 0
	for i in range(n - 2):
		sm += a[i] * j
		j += 1
	sm += a[-2] * j + a[-1] * j
	print(sm)


a = int(input())
l = [int(i) for i in input().split()]
l.sort()
s = sum(l)
for i in range(a):
	s += l[i] * (i + 1)
print(s - max(l))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = sorted(array())
s = sum(a)
score = s
for i in range(n - 1):
	score += s
	s -= a[i]
print(score)


import sys
from heapq import *
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	B = [-a for a in A]
	heapify(B)
	res = 0
	while len(B) > 1:
		ma1 = -heappop(B)
		ma2 = -heappop(B)
		res += ma1 + ma2
		heappush(B, -(ma1 + ma2))
	print(res + -B[0])
resolve()


inp = input()
n = int(inp)
line = input()
myarray = line.split(' ')
myarray = list(map(int, myarray))
myarray = sorted(myarray)
score = 0
if n == 1:
	print(int(myarray[0]))
elif n == 2:
	print(2 * (int(myarray[1]) + int(myarray[0])))
else:
	minimum = 0
	for x in range(len(myarray)):
		score = score + (x + 2) * int(myarray[x])
	score = score - int(int(myarray[n - 1]))
	print(score)


n = int(input())
s = input().split()
for i in range(len(s)):
	s[i] = int(s[i])
s.sort()
j = 0
k = 0
for i in s:
	j += 1
	k += i * j

def x(s):
	if len(s) < 2:
		return 0
	else:
		return sum(s) + x(s[1:])
print(sum(s) + k - s[len(s) - 1])


n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
ans = 0
l = len(nums)
if l == 1:
	print(nums[0])
else:
	for i in range(l - 2):
		ans += (i + 2) * nums[i]
	ans += (nums[-1] + nums[-2]) * l
	print(ans)


n = input()
n = int(n)
s = input()
a = [int(i) for i in s.split()]
a.sort()
total = 0
for i in range(len(a)):
	if i < len(a) - 2:
		total = total + a[i] * (i + 2)
	else:
		total = total + a[i] * n
print(total)


n = int(input())
a = sorted(map(int, input().split()))
t = 0
for x in range(1, n):
	t += a[x - 1] * (x + 1)
print(t + n * a[n - 1])


n = int(input())
line = input()
a = line.split()
nums = [int(x) for x in a]
nums.sort()
sums = 0
for i in range(n - 1):
	sums += nums[i] * (i + 2)
sums += nums[n - 1] * n
print(sums)


n = int(input())
a = [int(w) for w in input().split()]
a = sorted(a)
s = sum(a)
for i in range(len(a)):
	s += a[i] * (i + 1)
print(s - max(a))


n = int(input())
line = input().split()
data = [int(i) for i in line]
data.sort(reverse=True)
score = 0
if n >= 4:
	for i in range(2, len(data)):
		score = score + int(data[i]) * int(n - i + 1)
	score = score + int(int(n) * int(data[1]))
	score = score + int(int(n) * int(data[0]))
elif n == 3:
	score = score + int(data[2]) * 2
	score = score + int(3 * int(data[1]))
	score = score + int(3 * int(data[0]))
elif n == 2:
	score = score + int(2 * int(data[1])) + int(2 * int(data[0]))
elif n == 1:
	score = int(data[0])
print(score)


n = int(input())
l = sorted(list(map(int, input().split())))
s = 0
i = 0
while i < n:
	s += l[i] * min(i + 2, n)
	i += 1
print(s)


input()
q = [int(x) for x in input().split()]
q.sort()
s = delta = sum(q)
for item in q:
	s += delta
	delta -= item
print(s - q[-1])


n = int(input())
l1 = list(map(int, input().split()))
l1.sort()
s = 0
for i in range(0, n - 1):
	x = l1[i]
	s += (i + 2) * x
y = l1[-1]
s += y * n
print(s)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = sorted(LI())
	r = s = sum(a)
	r -= a[-1]
	for c in a:
		r += s
		s -= c
	return r
print(main())


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
l.reverse()
sc = l[0] * n
if n > 1:
	for i in range(1, n):
		sc += l[i] * n
		n -= 1
print(sc)


n = int(input())
inp = input().split()
for i in range(n):
	inp[i] = int(inp[i])
inp = sorted(inp)
ans = 0
for i in range(n):
	ans += inp[i]
su = ans
for i in range(n - 1):
	ans += su
	su -= inp[i]
print(ans)


n = int(input())
l = [int(y) for y in input().split()]
l.sort()
c = l[-1] * n
for i in range(n - 2, -1, -1):
	c += l[i] * (i + 2)
print(c)


x = int(input())
l = [int(x) for x in input().split()]
sum = 0
for i in l:
	sum += i
l1 = sorted(l)
result = sum * 2
for i in l1[:x - 2]:
	sum = sum - i
	result += sum
if x == 1:
	print(l[0])
else:
	print(result)


n = int(input())
s = input()
a = [int(x) for x in s.split()]
a.sort()
if n == 1:
	print(a[0])
else:
	ans = 0
	for x in range(n):
		ans += (x + 2) * a[x]
	ans = ans - a[n - 1]
	print(ans)


n = int(input())
A = list(map(int, input().split()))
A.sort()
if n == 1:
	print(*A)
elif n == 2:
	print((A[0] + A[1]) * 2)
else:
	k = 2
	s = 0
	for i in range(n - 1):
		s += k * A[i]
		k += 1
	s += A[-1] * (k - 1)
	print(s)


import sys, math, itertools, heapq, collections, bisect, string
input = lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8')
count = 0
n = int(input())
A = sorted(map(int, input().split()))
if n == 1:
	print(A[0])
	exit()
for i in range(n - 1):
	count += A[i] * (i + 2)
count += A[-1] * n
print(count)


n = int(input())
l = [int(i) for i in input().split()]
m = sorted(l)
z = 0
for i in range(n):
	z = z + int(m[i]) * (i + 2)
z = z - int(m[n - 1])
print(z)


from sys import stdin, stdout
n = int(stdin.readline())
A = list(map(int, stdin.readline().split()))
A.sort()
i = 1
total = 0
for j in range(n - 1):
	total = total + A[j] * (i + 1)
	i = i + 1
total = total + A[-1] * n
print(total)


n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
s = 0
for i in range(0, n - 1):
	s += int(a[i]) * (i + 2)
s += int(a[n - 1]) * n
print(s)


n = int(input())
listA = input().split()
sumTotal = 0
listB = []
for i in listA:
	a = int(i)
	sumTotal += a
	listB.append(a)
x = 0
sumA = 0 + sumTotal
listB.sort(reverse=True)
while x < n - 1:
	sum_1 = listB[-1]
	listB.pop()
	sumA -= sum_1
	sumTotal += sum_1 + sumA
	x += 1
print(sumTotal)


n = int(input())
a = input()
A = a.split()
A = map(int, A)
temp = []
for i in A:
	temp.append(i)
temp.sort()
score = -int(temp[n - 1])
for i in range(2, n + 2):
	score = score + i * int(temp[i - 2])
print(score)


n = int(input())
line = input().split()
L = []
sum = 0
for i in range(n):
	sum += int(line[i])
	L.append(int(line[i]))
L = sorted(L)
if n == 1:
	print(sum)
else:
	res = sum
	for i in range(n - 1):
		res += sum
		sum -= L[i]
	print(res)


n = int(input())
p = [int(i) for i in input().split()]
p.sort()
num = p[n - 1] * n
for i in range(n - 1):
	num += p[i] * (i + 2)
print(num)


n = int(input())
data = [int(x) for x in input().split()]
data.sort(reverse=True)
sum = 0
for x in range(len(data)):
	sum += (n + 1 - x) * data[x]
sum -= data[0]
print(sum)


n = int(input())
l = [int(x) for x in input().split(' ')]
sm = sum(l)
score = sm * n
l.sort()
l = l[::-1]
if len(l) > 2:
	for i in range(2, n):
		score -= l[i] * (i - 1)
print(score)


def solve():
	from heapq import heappush, heappop, heapify
	from sys import stdin
	f_i = stdin
	n = int(f_i.readline())
	A = list(map(int, f_i.readline().split()))
	if n == 1:
		return sum(A)
	A = [-a for a in A]
	heapify(A)
	ans = sum(A)
	while len(A) > 1:
		n1 = heappop(A)
		n2 = heappop(A)
		ans += n1 + n2
		heappush(A, n1 + n2)
	return -ans
print(solve())


num = int(input())
last = input().split()
last = sorted(list(map(int, last)))
ber = 0
for i in range(num):
	ber += last[i] * (i + 2)
print(ber - last[num - 1])


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
score = 0
score += sum(l)
for i in range(0, n - 1):
	score += l[i] * (i + 1)
score += l[n - 1] * (n - 1)
print(score)


n = int(input())
lists = [int(i) for i in input().split()]
lists = sorted(lists)
s = [0 for i in range(n)]
s[n - 1] = lists[n - 1]
for i in range(n - 2, -1, -1):
	s[i] = s[i + 1] + lists[i]
total = 0
for i in range(0, n - 1):
	total += s[i]
	total = total + lists[i]
total = total + lists[n - 1]
print(total)


n = int(input())
L = list(map(int, input().split()))
L.sort()
score = 0
for i in range(len(L)):
	score += L[i] * (i + 2)
score -= L[-1]
print(score)


n = int(input())
a = list(map(int, input().split()))
a.sort()
j = n
i = n - 1
s = j * a[i]
while i > 0:
	s += j * a[i - 1]
	j -= 1
	i -= 1
print(s)


import heapq
n = int(input())
a = list(map(lambda x: -int(x), input().split()))
heapq.heapify(a)
ans = 0
for i in range(n - 1):
	x = heapq.heappop(a)
	y = heapq.heappop(a)
	ans += x + y
	heapq.heappush(a, x + y)
print(-ans - sum(a))


n = int(input())
line = input()
line = line.split()
for i in range(n):
	line[i] = int(line[i])
line.sort()
sum_all = 0
for i in range(n):
	sum_all = sum_all + int(line[i])
if n == 1:
	print(sum_all)
elif n == 2:
	print(2 * sum_all)
else:
	max_sum = sum_all * n
	for i in range(n - 1):
		max_sum = max_sum - int(line[i]) * (n - i - 2)
	print(max_sum)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
s = 0
t = 0
for i in range(n):
	s = s + a[i]
t = s * n
if n >= 3:
	for i in range(n - 2):
		t = t - a[i] * (n - 2 - i)
else:
	t = t
print(t)


n = int(input())
list = [int(k) for k in input().split()]
list = sorted(list)
total = 0
for i in range(n):
	total += list[i] * (i + 2)
total -= list[i]
print(total)


n = int(input())
numbers = sorted([int(i) for i in input().split()])
ans = 0
for i in range(n):
	ans += numbers[i] * (i + 2)
ans -= numbers[-1]
print(ans)


import copy
n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
ma = n * a[n - 1]
for i in range(n - 1):
	ma += (i + 2) * a[i]
print(ma)


import re
n = int(input())
m = input()
r = re.split('\\s+', m)
s = []
for i in range(n):
	s.append(int(r[i]))
s.sort()
sum = 0
for j in range(n):
	if j <= n - 2:
		sum += s[j] * (j + 2)
	else:
		sum += s[j] * (j + 1)
print(sum)


n = int(input()) - 1
x = 0
l = list(map(int, input().split()))
l.sort(reverse=True)
for (ii, i) in enumerate(l):
	if ii < 2:
		x += i * (n + 1)
	else:
		x += i * n
		n -= 1
print(x)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
res = n * l.pop()
for (i, a) in zip(range(2, n + 1), l):
	res += i * a
print(res)


n = int(input())
list = input().strip().split()
list = [int(i) for i in list]
list.sort()
list_1 = [list[i] * (i + 2) for i in range(0, n)]
print(sum(list_1) - list[n - 1])


n = int(input())
ls = sorted(list(map(int, input().split())))
if n == 1:
	print(ls[0])
elif n == 2:
	print(sum(ls) * 2)
else:
	ans = 0
	for i in range(n):
		ans += (i + 2) * ls[i]
	ans -= ls[-1]
	print(ans)


n = int(input())
num = list(map(int, input().split()))
num.sort(reverse=True)
psum = [0] * n
psum[0] = num[0]
for i in range(1, n):
	psum[i] = psum[i - 1] + num[i]
print(sum(psum[1:]) + psum[n - 1])


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
S = 0
for i in range(n):
	S += nums[i] * (i + 2)
S -= nums[-1]
print(S)


def apple(lst, score):
	sm = sum(lst)
	x = 0
	for i in range(n):
		score += sm + x
		sm = sm - lst[i]
		x = lst[i]
	print(score)
n = int(input())
lst = sorted(list(map(int, input().split())))
apple(lst, 0)


input()
a = list(map(int, input().split()))
a.sort()
s = 0
for i in enumerate(a, 2):
	s += i[0] * i[1]
print(s - a[-1])


n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
if n == 1:
	print(l[0])
else:
	s = l[0] * n + l[1] * n
	p = n - 1
	for i in range(2, n):
		s += l[i] * p
		p -= 1
	print(s)


total = 0
import math
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
total = 0
t = n
for i in l[1:]:
	total += t * i
	t -= 1
total += n * l[0]
print(total)


from itertools import accumulate
from collections import *

def arr_sum(arr):
	arr.appendleft(0)
	return list(accumulate(arr, lambda x, y: x + y))
(n, a) = (int(input()), deque(sorted(map(int, input().split()))))
arr = arr_sum(a)
ans = arr[-1]
if n > 1:
	for i in range(n - 1):
		ans += arr[-1] - arr[i]
print(ans)


n = int(input())
arr = sorted([int(x) for x in input().split()])
ans = 0
s = sum(arr)
at = 0
while at < len(arr):
	ans += s
	if at != len(arr) - 1:
		ans += arr[at]
	s -= arr[at]
	at += 1
print(ans)


n = int(input())
a = list(map(int, input().rstrip().split()))
a.sort(reverse=True)
t = 0
t += n * a[0]
for i in range(n - 1):
	t += a[i + 1] * (n - i)
print(t)


n = int(input())
s = input()
x = list()
x = s.split()
y = sorted(x, key=int)
ans = 0
for i in range(n):
	ans += int(y[i]) * (i + 2)
ans -= int(y[n - 1])
print(ans)


n = int(input())
l = sorted(list(map(int, input().split())))
s = -l[-1]
for (i, e) in enumerate(l):
	s += (i + 2) * e
print(s)


import sys, os

def myreadline():
	testFile = ''
	if testFile:
		if not hasattr(myreadline, 'fTest'):
			myreadline.fTest = open(os.path.join(os.path.dirname(__file__), testFile))
		return myreadline.fTest.readline()
	else:
		return input()

def myreadlineint():
	return [int(x) for x in myreadline().split()]
(n,) = myreadlineint()
l = myreadlineint()
l.sort()
sm = sum(l)
res = 0
res += sm * 2
for x in l:
	sm -= x
	res += sm
res -= l[len(l) - 1]
print(res)


n = int(input())
inList = input().split()
aList = []
for a in inList:
	aList.append(int(a))
aList.sort()
res = 0
for i in range(len(aList)):
	res += aList[i] * (i + 2)
print(res - aList[-1])


n = int(input())
A = [int(k) for k in input().split()]
A.sort()
total = 0
for i in range(n):
	total += A[i] * (i + 2)
total -= A[n - 1]
print(total)


n = int(input())
a = list(map(int, input().split()))
f = 0
sum = 0
count = 0
for i in range(n):
	sum += a[i]
a.sort(reverse=True)
while len(a):
	count += sum + f
	f = a.pop()
	sum -= f
print(count)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [i + 2 for i in range(n - 1)] + [n]
c = zip(a, b)
print(sum([x * y for (x, y) in c]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 0
c = sum(a)
x += c
for i in range(n):
	c -= a[i]
	x += a[i] + c
print(x - a[-1])


n = int(input())
t = 0
line = [int(i) for i in input().split()]
line.sort()
for i in range(1, n + 1):
	t += (i + 1) * line[i - 1]
t -= line[-1]
print(t)


A = int(input())
B = input()
num = B.split(' ')
numreal = [int(i) for i in num]
numreal.sort()
sum1 = sum(numreal)
for i in range(0, A - 1):
	sum1 += numreal[i] * (i + 1)
sum1 += numreal[A - 1] * (A - 1)
print(sum1)


n = int(input())
A = sorted(map(int, input().split()))
max_score = subsum = sum(A)
for i in range(n - 1):
	(max_score, subsum) = (max_score + subsum, subsum - A[i])
print(max_score)


def read():
	n = int(input())
	nums = [int(x) for x in input().split(' ')]
	return nums

def solve_dyn(arr):
	arr.sort(reverse=True)
	dyn = [0] * (len(arr) + 1)
	sums = [0] * (len(arr) + 1)
	dyn[1] = arr[0]
	sums[1] = arr[0]
	for i in range(2, len(arr) + 1):
		sums[i] = sums[i - 1] + arr[i - 1]
		dyn[i] = dyn[i - 1] + sums[i] + arr[i - 1]
	return dyn[len(arr)]
print(solve_dyn(read()))


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
if n == 1:
	print(sum(line))
elif n == 2:
	print(2 * sum(line))
else:
	line.sort()
	value = 0
	factor = 1
	for i in range(n - 1):
		factor += 1
		value += factor * line[i]
	value += factor * line[n - 1]
	print(value)


n = int(input())
a = list(map(int, input().split()))
ans = 0
if n == 1:
	ans = sum(a)
else:
	a.sort(reverse=True)
	ans = n * a[0]
	i = 1
	for i in range(1, n):
		ans += (n - i + 1) * a[i]
		i += 1
print(ans)


l = int(input())
a = [int(i) for i in input().split()]
a.sort()
s = 0
for i in range(l):
	s += a[i] * (i + 2)
print([s - a[l - 1], a[0]][l == 1])


n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
o = 0
a.sort(reverse=True)
s = ans
while a:
	o = a.pop()
	s -= o
	ans += s + [o, 0][a == []]
print(ans)


n = int(input())
table = [int(x) for x in input().split(' ')]
table.sort()
count = 0
for (k, v) in enumerate(table, start=2):
	count += k * v
count -= table[n - 1]
print(count)


while True:
	try:
		n = int(input())
		l = [int(i) for i in input().split()]
		l = sorted(l)
		s = 0
		for i in range(len(l) - 1):
			s += (i + 2) * l[i]
		s += n * l[n - 1]
		print(s)
	except EOFError:
		break


n = int(input())
l = list(map(int, input().rstrip().split(' ')))
l.sort()
s = sum(l)
t = s
for i in range(n - 1):
	s = s - l[i]
	t = t + l[i] + s
print(t)


n = int(input())
a = list(map(int, input().split()))
a.sort()
s = sum(a)
total = s
for i in range(n - 1):
	s = s + a[i]
	total = total - a[i]
	s = s + total
print(s)


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
sum = 0
score = 0
for i in a:
	sum += i
if n == 1:
	score += sum
else:
	score += 2 * sum
for j in range(n - 2):
	sum -= b[j]
	score += sum
print(score)


n = int(input())
numbers = sorted(list(map(int, input().strip().split())))
total = sum(numbers)
answer = total
for i in range(n - 1):
	answer += total
	total -= numbers[i]
print(answer)


n = int(input())
m = sorted(list(map(int, input().split())))
s = sum(m)
if n != 1:
	for i in range(n - 1):
		s += m[i] * (i + 1)
	s += m[n - 1] * (n - 1)
print(s)


import sys
from heapq import heappush, heappop, heapify

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A = [-a for a in A]
heapify(A)
ans = 0
while len(A) > 1:
	a = heappop(A)
	b = heappop(A)
	ans += -(a + b)
	heappush(A, a + b)
ans += -A[0]
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
s = sum(a)
res = s
while len(a) > 1:
	res += s
	s -= a.pop()
print(res)


n = int(input())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
if len(l) == 1:
	print(l[0])
elif len(l) == 2:
	print(2 * sum(l))
else:
	t = -l[0]
	for i in l:
		t += i * (n + 1)
		n -= 1
	print(t)


from heapq import *
N = input()
A = list(map(int, input().split()))
S = sum(A)
heapify(A)
res = S
while len(A) > 1:
	A_min = heappop(A)
	S -= A_min
	res += S + A_min
print(res)


count = 0
n = int(input())
A = sorted(map(int, input().split()))
if n == 1:
	print(A[0])
	exit()
for i in range(n - 1):
	count += A[i] * (i + 2)
count += A[-1] * n
print(count)


n = int(input())
m = sorted(list(map(int, input().split())))
score = 0
if len(m) == 1:
	print(m[0])
else:
	for j in range(len(m) - 1):
		score += m[j] * (j + 2)
	score += m[-1] * len(m)
	print(score)


import sys
t = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
s = 0
if t == 1:
	print(arr[0])
	sys.exit()
for i in range(len(arr) - 1):
	s += (i + 2) * arr[i]
print(s + t * arr[i + 1])


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
a.sort()
m = -a[n - 1]
for i in range(n):
	m += (i + 2) * a[i]
print(m)


def total(A):
	x = 0
	for i in A:
		x += i
	return x

def result(A):
	x = 0
	for i in range(len(A)):
		x += A[i] * (i + 1)
	return x
n = int(input())
A = [int(i) for i in input().split()]
A.sort()
print(total(A) + result(A) - A[-1])


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
flush = stdout.flush
OUT = []

def write(item, sep=' '):
	if type(item) is int:
		OUT.append(str(item))
	elif type(item) is list:
		if type(item[0]) is int:
			OUT.append(sep.join(map(str, item)))
		else:
			OUT.append(sep.join(item))
	else:
		OUT.append(item)

def PRINT():
	print('\n'.join(OUT))
GI = lambda : int(input())
GS = lambda : input()[:-1]
gi = lambda : list(map(int, input().split()))
gs = lambda : input().split()
n = GI()
arr = sorted(gi())[::-1]
s = A = sum(arr)
while len(arr) > 1:
	s += A
	A -= arr.pop()
write(s)
PRINT()