#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int re()
{
int x=0;
char y=getchar();
while(y>='0'&&y<='9')x=(x<<3)+(x<<1)+y-'0',y=getchar();
return x;
}
priority_queue <int,vector<int>,greater<> > q;
int main(){
int n,ans=0,z;
n=re();
for(int i=1;i<=n;i++)
{
z=re();
q.push(z);
}
for(int i=1;i<=n-1;i++)
{
int x=q.top(),temp;
q.pop();
int y=q.top();
q.pop();
temp=x+y;
ans+=temp;
q.push(temp);
}
cout<<ans<<endl;
}