#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		priority_queue<int, vector<int>, greater<int> > PQue;
		for(int i = 0; i < n; ++i)
		{
			int input;
			cin >>input;
			PQue.push(input);
		}
		vector<int> wait_time(n + 1);
		wait_time[0] = 0;
		int pos = 0;
		while(!PQue.empty())
		{
			wait_time[pos + 1] = PQue.top() + wait_time[pos];
			PQue.pop();
			pos++;
		}
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			sum += wait_time[i];
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}