#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    vector<long long> n;
    long long t, res = 0;
    cin >> t;
    while (cin >> t, t != 0)
        n.push_back(t);
    sort(n.begin(), n.end());
    for (int i = 0; i < n.size() - 1; i++) {
        t = t + n[i];
        res += t;
    }
    cout << res << endl;

    return 0;
}