#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 100
using namespace std;
int n;
int data[MAX_N + 1];

int calcSum() {
    int tmp[n+1]; memset(tmp, 0, sizeof(tmp));
    for(int r = 1; r < n+1; r++) {
        (tmp[r] = tmp[r-1] + data[r-1]);
        //cout << "tmp[" << (r-1) << "] + data[" << r-1 << "]" << endl;
    }
    return(accumulate(tmp, tmp+n, 0));
}

void solve() {
    sort(data, data+n);
    printf("%d\n", calcSum());
}

int main(void) {
    while(cin >> n, n) {
        memset(data, INF, sizeof(data));
        for(int r = 0; r < n; r++) {
            cin >> data[r];
        }
        solve();
    }
    return(0);
}