#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
	
	vector<int> cus;
	vector<int> wait;
	int i,n,sum,temp,num;
	
	while(1){
		
		i=n=sum=temp=num=0;
		
		cin>>num;
		
		if(num==0){
			break;
		}
		
		for(int k=0;k<=num;k++){
		
			cin>>n;
			if(i>1000){
				break;
			}
			cus.push_back(n);
			i++;
		}
	
		sort(cus.begin(),cus.end());

		for(unsigned int k=0;k<cus.size();k++){
			for(unsigned int m=0;m<k;m++){
				temp=temp+cus[m];
			}
			wait.push_back(temp);
			temp=0;
		}
	
		for(unsigned int k=0;k<wait.size();k++){
			sum=sum+wait[k];
		}
		cout<<sum<<endl;
	}
}