#include <bits/stdc++.h>
using namespace std;
priority_queue< int, vector <int>, greater <int> > q;
int main ()
{
ios::sync_with_stdio(false);
int n;
cin>>n;
for (int i=1;i<=n;i++) {
int x; cin>>x;
q.push(x);
}
int sum=0;
for (int i=1;i<=n-1;i++) {
int x=q.top(); q.pop();
int y=q.top(); q.pop();
x+=y;
sum+=x;
q.push(x);
}
cout<<sum<<endl;
return 0;
}
/*
input :
5
1 2 2 5 9
output:
37
*/
抓住青春的尾巴。。。