#include<iostream>
#include<queue>
using namespace std;
priority_queue<long long,vector<long long>,greater<long long>> q;
int n;
long long ans=0;
void ch()
{
for(int i=1;i<n;i++)
{
long long x=q.top();
q.pop();
long long y=q.top();
q.pop();
x=x+y;
ans+=x;
q.push(x);
}
}
int main()
{
freopen("fruit.in","r",stdin);
freopen("fruit.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
long long a;
cin>>a;
q.push(a);
}
ch();
cout<<ans;
return 0;
}