#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> >que;
int n,j=0;
int x;
long long c[10000];
long long h;
int main()
{ freopen("fruit.in","r",stdin);
freopen("fruit.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&x);
que.push(x);
}
while(que.size()!=1)
{
int y=que.top();
que.pop();
int yy=que.top();
que.pop();
int yyy=y+yy;
++j;
c[j]=yyy;
que.push(yyy);
}
for(int i=1;i<=j;++i)
h+=c[i];
printf("%ld",h);
return 0;
}