#include <bits/stdc++.h>
using namespace std;
int main()
{
priority_queue<int,vector<int>,greater<int>>heap;
int n;
cin >> n;
for(int i = 0,x;i < n;i ++){
cin >> x;
heap.push(x);
}
int sum = 0;
while(heap.size() > 1){
int f1 = heap.top();
heap.pop();
int f2 = heap.top();
heap.pop();
heap.push(f1 + f2);
sum = sum + f1 + f2;
}
cout << sum << endl;
return 0;
}