#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll ans=0;
ll n=0,a[200005],b[200005];
int main(){
cin>>n;
for(ll k=1;k<=n;k++)
    cin>>a[k];
    sort(a+1,a+n+1);
b[n]++;
ll j=n;
for(ll k=n-1;k>=1;k--){
    while(b[j]==0LL){
        j--;
    }
    ans+=a[j];
    b[j]--;
    b[k]+=2LL;
}
cout<<ans;
return 0;
}
