#include <bits/stdc++.h>
using namespace std;
#define int long long
int box[100010];
int n, cnt;
queue <int> q1, q2;
int read(){
int op = 1;
int x = 0;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-')
op = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
op = op * 10 + (ch - '0');
ch = getchar();
}
return x *= op;
}
int qfront(){
if(q2.empty() || (!q1.empty() && q1.front() < q2.front())){
int x = q1.front();
q1.pop();
return x;
}
else{
int x = q2.front();
q2.pop();
return x;
}
}
signed main(){
int n = read();
cnt = 0;
for(int i = 1; i <= n; i++){
int c = read();
box[c] ++;
}
for(int i = 1; i <= 100000; i++)
for(int j = 1; j <= box[i]; j++)
q1.push(i);
for(int i = 1; i < n; i++){
int x = qfront();
int y = qfront();
q2.push(x + y), cnt += x + y;
}
cout << cnt << "\n";
return 0;
}