#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> v;
		for (int i = 0; i < n; ++i) {
			int a; cin >> a;
			v.push_back(a);
		}

		sort( v.begin(), v.end() );

		for (int i = 0; i < n-1; ++i)
			v[i+1] += v[i];

		int s = 0;
		for (int i = 0; i < n-1; ++i)
			s += v[i];

		cout << s << endl;
	}
}