#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int >,greater<int > > b;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline void write(int x){
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return ;
}
int main(){
std::ios::sync_with_stdio(false);
int n,a[10001]={};
n=read();
for(int i=1;i<=n;i++){
a[i]=read();
b.push(a[i]);
}
int sum=0;
while(b.size()!=1){
for(int i=1;i<=2;i++){
sum+=b.top();
b.pop();
}
b.push(sum);
}
cout<<sum;
return 0;
}