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

Solution in JAVA (judge verdict: Accepted)

import java.io.*;
import java.util.*;


public class Main {
	public static void main(String[] args) {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));       
		try {
			String line;
			while((line = r.readLine())!=null){
				if(line.length()<1) break;
				int N = Integer.parseInt(line);
				String[] pline = r.readLine().split(" ");
				int[] p = new int[N];
				for(int i=0;i<N;i++){
					p[i] = Integer.parseInt(pline[i]);
				}
				
				Arrays.sort(p);
				
				int time = 0;
				
				for(int i=0;i<N;i++){
					time += p[i]*(N-i);
				}
				
				System.out.println(time);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}