#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define MAX 20010
using namespace std;
long long Q[MAX];
long long Index;
long long Cost;
int cmp(const void *a,const void *b)
{
return *(int *)b - *(int *)a;
}
void Insert(long long temp)
{
if(Index < 2) return;
for(int i = Index - 2;i >= 0;i--){
if(temp > Q[i])
Q[i+1] = Q[i];
else
{
Q[i+1] = temp;
return;
}
}
Q[0] = temp;
}
int main()
{
int n;
cin>>n;
Cost = 0;
Index = n;
for(int i = 0;i < n;i++)
cin>>Q[i];
qsort(Q,Index,sizeof(long long),cmp);
while(Index > 1){
long long temp = Q[Index-1] + Q[Index-2];
Cost += temp;
Index--;
Insert(temp);
}
cout<<Cost<<endl;
return 0;
}