import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
private int []array;
private int n, result;
Main() {
Scanner in = new Scanner(new BufferedInputStream(System.in));
result = 0;
n = Integer.parseInt(in.next());
array = new int [n];
for(int i=0; i<n; i++) {
array[i] = Integer.parseInt(in.next());
}
in.close();
}
private void print() {
// TODO Auto-generated method stub
System.out.println(result);
}
private void run() {
int pos, temp;
Arrays.sort(array);
for(int i=1; i<n; i++) {
temp = array[i] + array[i-1];
result += temp;
pos = i+1;
while(pos < n && array[pos] < temp) {
array[pos-1] = array[pos];
pos ++;
}
array[pos-1] = temp;
}
print();
}
public static void main(String[] args) {
new Main().run();
}
}