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

int main()
{
	int n,t;
	unsigned int ans;
	while(cin >> n, n)
	{
		vector<unsigned int> v;
		while(n--)
		{
			cin >> t;
			v.push_back(t);
		}

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

		ans=0;
		for(int i=0; i<v.size()-1; i++)
		{
			ans    += v[i];
			v[i+1] += v[i];
		}

		cout << ans << endl;
	}
}