#include <iostream>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	while(cin >> n) {
		int a[10000+10] = {};
		int i = 0;
		int x;
		while(cin >> x && x) {
			a[i] = x;
			i++;
		}
		sort(a,a+n);

		long long ret = 0;
		rep2(j,1,n) {
			a[j] += a[j-1];
		}
		rep(j,n-1) {
			ret += a[j];
		}
		cout << ret << endl;
	}
	return 0;
}