#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n, a[10000], b[10000], s, i;
	while (cin >> n && n)
	{
		for (i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a+n);
		for (i = 1, b[0] = s = 0; i < n; i++)
			b[i] = b[i-1]+a[i-1], s += b[i];
		cout << s << endl;
	}
}