import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] A = new int[N];
int[] answer = new int[N];
for (int i = 0; i < N; i++) {
A[i] = sc.nextInt();
}
for (int i = 0; i < N; i++) {
int point = i;
int value = A[i];
for (int j = i - 1; j >= 0; j--) {
if (A[j] < A[i]) {
point = j + 1;
break;
}
if (j == 0) {
point = 0;
}
}
for (int j = i; j > point; j--) {
A[j] = A[j - 1];
}
A[point] = value;
}
answer[0] = A[0];
for (int i = 1; i < N; i++) {
answer[i] = answer[i - 1] + A[i];
}
int sum = 0;
for (int i = 0; i < N; i++) {
sum = sum + answer[i];
}
System.out.println(sum);
}
}
그냥 Arrays.sort()로 풀어도 되는데 삽입정렬 연습하느라 삽입정렬로 풀었다.