#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int>> pq;
long long x;
long long a,s,ans,d;
int main (){
int n;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> x;
pq.push(x);
}
for (int i = 1; i <= n; i++){
a=pq.top();
pq.pop();
s=pq.top();
pq.pop();
d=a+s;
pq.push(d);
ans+=d;
}
cout << ans << endl;
return 0;
}