#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int n;
priority_queue<int> pq;
int res;
int main () {
freopen ("fruit.in", "r", stdin);
freopen ("fruit.out", "w", stdout);
cin >> n;
int num;
for (int i = 1; i <= n; i++) {
cin >> num;
pq.push(-num);
}
for (int i = 1; i < n; i++) {
int one = pq.top();
pq.pop();
int two = pq.top();
pq.pop();
int num = one + two;
pq.push(num);
res -= num;
}
cout << res << endl;
return 0;
}