Problem:


Problem J: Cheating on ICPC

 Peter loves any kinds of cheating.  A week before ICPC, he broke into Doctor's PC and sneaked a look at all the problems that would be given in ICPC.  He solved the problems, printed programs out, and brought into ICPC.  Since electronic preparation is strictly prohibited, he had to type these programs again during the contest.

  Although he believes that he can solve every problems thanks to carefully debugged programs, he still has to find an optimal strategy to make certain of his victory.

  Teams are ranked by following rules.

  
   Team that solved more problems is ranked higher.

  
  In case of tie (solved same number of problems), team that received less Penalty is ranked higher.

  Here, Penalty is calculated by these rules.

  
   When the team solves a problem, time that the team spent to solve it (i.e. (time of submission) - (time of beginning of the contest)) are added to penalty.

  
  For each submittion that doesn't solve a problem, 20 minutes of Penalty are added.  However, if the problem wasn't solved eventually, Penalty for it is not added.

  You must find that order of solving will affect result of contest.  For example, there are three problem named A, B, and C, which takes 10 minutes, 20 minutes, and 30 minutes to solve, respectively.  If you solve A, B, and C in this order, Penalty will be 10 + 30 + 60 = 100 minutes.  However, If you do in reverse order, 30 + 50 + 60 = 140 minutes of Penalty will be given.

  Peter can easily estimate time to need to solve each problem (actually it depends only on length of his program.)  You, Peter's teammate, are asked to calculate minimal possible Penalty when he solve all the problems.

Input

Input file consists of multiple datasets.  The first line of a dataset is non-negative integer N (0 ≤ N  ≤ 100) which stands for number of problem.  Next N Integers P[1], P[2], ..., P[N] (0 ≤ P[i] ≤ 10800) represents time to solve problems.

  Input ends with EOF. The number of datasets is less than or equal to 100.

Output

Output minimal possible Penalty, one line for one dataset.

Sample Input

3
10 20 30
7
56 26 62 43 25 80 7

Output for the Sample Input

100
873



Sample input:
3
10 20 30
7
56 26 62 43 25 80 7


Sample output:
100
873

Submission status: Wrong Answer

Solution code:
n=int(input())
print(sum((n-i)*x for i,x in enumerate(sorted(list(map(int,input().split()))))))

Submission status: Accepted

Solution code:
while True:
    N=0
    times=[]
    try:
        N=int(input())
        times=list(map(int,input().split()))
    except:
        break

    times.sort(reverse=True)
    ans=0
    for i in range(len(times)):
        ans+=(i+1)*times[i]
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    try:n=int(input())
    except:break
    print(sum((n-i)*x for i,x in enumerate(sorted(list(map(int,input().split()))))))

Submission status: Accepted

Solution code:
while True:
    try:
        _= int(input())
    except:
        break
    t= 0
    ans= []
    for v in sorted(list(map(int, input().split()))):
        t+= v
        ans.append(t)
    print(sum(ans))

Submission status: Accepted

Solution code:
from sys import stdin
for num in stdin:
    penalty = [0] * int(num)
    time = [int(i) for i in stdin.readline().split()]
    time.sort()
    penalty[0] = time[0]
    for j in range(1,len(time)):
        penalty[j] += penalty[j-1] + time[j]
    print(sum(penalty))

Submission status: Accepted

Solution code:
while True:
    try:
        num = int(input())
    except:
        break
    times = list(map(int, input().split()))
    times.sort()
    ans = sum([(num-index) * time for index, time in enumerate(times)])
    print(ans)

Submission status: Accepted

Solution code:
import sys

def sumItUp(List):
    result = []
    for i in range(0,len(List)):
        result.append(sum(List[0:i+1]))
    return sum(result)

List = []
for i in sys.stdin:
    List.append(i)

for i in range(1,len(List),2):
    List[i] = List[i].split()
    for j in range(0,len(List[i])):
        List[i][j] = int(List[i][j])
    List[i] = sorted(List[i])
    print(sumItUp(List[i]))

Submission status: Accepted

Solution code:
# AOJ 1018: Cheating on ICPC
# Python3 2018.7.4 bal4u

while True:
	try: n = int(input())
	except: break
	p = sorted(list(map(int, input().split())))
	ans, k = 0, n
	for x in p:
		ans += x*k
		k -= 1
	print(ans)

Submission status: Accepted

Solution code:
while True:
    try:
        n=input()
    except EOFError:
        break
    L=sorted(map(int,raw_input().split()))
    for i in range(1,n):
        L[i]+=L[i-1]
    print sum(L)

Submission status: Accepted

Solution code:
import sys

def solve():
    
    while True:
        try:
            n = input()        
        except EOFError:
            break
        d = sorted(map(int,raw_input().split()))
        for i in range(1,n):
            d[i] += d[i-1]
        print sum(d)
                            
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
while 1:
	try:
		n=input()
		p=sorted(map(int,raw_input().split()))
		print sum([sum(p[:i+1]) for i in range(n)])
	except:
		break

Submission status: Accepted

Solution code:
try:
    while 1:
        N = int(input())
        *A, = map(int, input().split())
        A.sort()
        ans = 0; su = 0
        for a in A:
            su += a; ans += su
        print(ans)
except EOFError:
    ...

Submission status: Accepted

Solution code:
import fileinput
tokens = []
for line in fileinput.input():
    tokens.append(list(map(int, line.strip().split())))
for i in range(len(tokens)):
    if i%2==0:
        continue
    else:
        S = 0
        token_s = sorted(tokens[i])
        for i,name in enumerate(token_s):
            S += name*(len(token_s)-i)
        print(S)

Submission status: Accepted

Solution code:
while True:
    try:
        n=int(input())
        A=sorted(list(map(int,input().split())))
        S=0
        K=0
        for i in range(n):
            S+=A[i]*(n-i)
        print(S)
    except EOFError:
        break

Submission status: Accepted

Solution code:

for j in range(100):

    n = int(input())

    a = list(map(int,input().split()))
    a.sort()

    now = 0
    ans = 0

    for i in range(n):
        now += a[i]
        ans += now

    print (ans)

Submission status: Accepted

Solution code:
while True:
	try:
		n=int(input())
	except:
		exit()
	a=list(map(int,input().split()))
	a.sort()
	for i in range(n-1):
		a[i+1]+=a[i]
	print(sum(a))

Submission status: Runtime Error

Solution code:
import sys

def solve():
    
    while True:
        try:
            n = input()
        
        except EOFError:
            break
        d = sorted(map(int,raw_input().split()))
        for i in range(1,n):
            d[i] += d[i-1]
        print sum(d)
                            
if __name__ == "__main__":
    solve()
    n = raw_input()