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: competition

Starter code:

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

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



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())
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)


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())
a = [int(x) for x in input().split()]
a.sort()

print(sum([(i+1)*a[i] for i in range(n)])+sum(a[:-1]))


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())
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)


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)


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)


import sys, os

def myreadline():

    #testFile = "461A-t"
    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)
#print(sm)
res = 0
res += sm*2
for x in l:
    sm -= x
    #print(sm)
    res += sm
res -= l[len(l)-1]

print(res)












input()
t = list(map(int, input().split()))
t.sort()
print(sum(i * x for i, x in enumerate(t, 2)) - t[-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()

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])

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]

#ans = sum_l(l2)
#for i in range(l1-1):
#    ans += sum_l(l2)
#    l2.pop(0)
    
print (ans)
    




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())
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)

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)

#!/usr/bin/env python
# encoding: utf-8

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


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



sum=0
if n!=1:
    for i in range(2,n+1):
        sum+=i*l[i-2]
    sum+=n*l[n-1]
    print(sum)
else: print(l[0])

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):
    #print(ans)
   # print(data[i:])
    ans+=sum
    sum-=data[i]

print(ans)

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])


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())
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)


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())