#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        int ans = 0;
        priority_queue<int, vector<int>, greater<int>> pq;
        while (n--) {
            int x;
            cin >> x;
            pq.push(x);
        }
        while (pq.size() > 1) {
            int a = pq.top();
            pq.pop();
            int b = pq.top();
            pq.pop();
            int x = a + b;
            ans += x;
            pq.push(x);
        }
        cout << ans << endl;
    }
    return 0;
}