#include<iostream>
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> >Q;
int total;
int main(){
int n,x;
cin >> n;
while(n--){
cin >> x;
Q.push(x);
}
while(Q.size() != 1){
int sum = 0;
sum += Q.top();
Q.pop();
sum += Q.top();
Q.pop();
Q.push(sum);
total += sum;
}
cout << total << endl;
return 0;
}
07-14
2052
10-13
381