#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
	while (1) {
		int n, t[10005], s[10005];
		long long int w;
		w = 0;
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> t[i];
		}
		sort(t, t + n);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				s[i] = s[i] + t[j];
			}
			w += s[i];
			//cout << s[i] << endl;
		}
		cout << w << endl;
	}
	return 0;
}