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

int main(){
	int n;
	while(cin >> n , n){
		int time[10010];
		int total[10010]={0};
		for(int i=1;i<=n;i++){
			cin >> time[i-1];
		}
		sort(time,time+n);
		int ans = 0;
		for(int i=1;i<=n;i++){
			total[i] = time[i-1] + total[i-1];
			ans += total[i-1];
		}
		cout << ans << endl;
	}
}