#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <numeric>
#include <ctime>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <map>

using namespace std;

int solve(priority_queue<int, vector<int>, greater<int> > &q)
{
	int ret, sum;

	ret = 0; sum = 0;
	while (q.size() != 1){
		sum += q.top();
		ret += sum;
		q.pop();
	}
	return ret;
}

int main()
{
	
	int n;
	while (true){
		cin >> n;
		if (n == 0) break;
		priority_queue<int, vector<int>, greater<int> > q;
		int buf;
		for (int i = 0; i < n; i++){
			cin >> buf;
			q.push(buf);
		}

		cout << solve(q) << endl;
	}

	return 0;
}