#include<iostream>
#include<queue>
#define int long long
using namespace std;
queue<int> q1, q2;
int read() {
int num = 0, ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
while(ch <= '9' && ch >= '0') num = (num << 3) + (num << 1) +(ch ^ 48), ch = getchar();
return num;
}
int n, i, tmp, tmpp, sum;
int t[100005];
inline int get() {
if(q1.empty()) {
tmp = q2.front(), q2.pop();
return tmp;
}
if(q1.front() < q2.front()) tmp = q1.front(), q1.pop();
else tmp = q2.front(), q2.pop();
return tmp;
}
signed main() {
n = read();
for(int i = 1; i <= n; ++ i) tmp = read(), ++ t[tmp], tmpp = max(tmp, tmpp);
for(int i = 1; i <= tmpp; ++ i) while(t[i] --) q1.push(i);
sum += q1.front(); q1.pop(); sum += q1.front(); q1.pop(); q2.push(sum);
for(int i = 2, x, y; i < n; ++ i) {
x = get(); y = get();
sum += x + y; q2.push(x + y);
}
cout << sum;
return 0;
}