//KZNS
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
//
ifstream fin ("poker.in");
ofstream fout ("poker.out");
class poi {
public:
inline bool operator () (int a, int b) {
return a > b;
}
};
//
priority_queue<int, vector<int>, poi> ls;
int N;
//
int main() {
fin >> N;
int u;
for (int i = 0; i < N; i++) {
fin >> u;
ls.push(u);
}
int a, b;
int ed = 0;
for(int i = 1; i < N; i++) {
a = ls.top();
ls.pop();
b = ls.top();
ls.pop();
u = a+b;
ls.push(u);
ed += u;
}
fout << ed;
return 0;
}
//UBWH