rt.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
queue<ll> q,q2;
int n,cnt[205];
ll ans;
inline int getint(){
int res=0;
char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9'){
res=(res<<3)+(res<<1)+ch-'0';
ch=getchar();
}
return res;
}
inline ll getMin(){
if(q.empty()){
ll res=q2.front();
q2.pop();
return res;
}
if(q2.empty()){
ll res=q.front();
q.pop();
return res;
}
if(q.front()<q2.front()){
ll res=q.front();
q.pop();
return res;
}
ll res=q2.front();
q2.pop();
return res;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
n=getint();
for(int i=1,a;i<=n;++i){
a=getint();
++cnt[a];
}
for(int i=1;i<=100000;++i)
while(cnt[i]){
q.push(i);
--cnt[i];
}
for(int i=2;i<=n;++i){
ll x=getMin(),y=getMin();
ans+=x+y;
q2.push(x+y);
}
cout<<ans;
return 0;
}