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

int main(){
	priority_queue<int,vector<int>,greater<int> >que;
	vector<int> vec;
	int n,p;
	while(cin>>n){
		if(n==0)break;
		for(int j=0;j<n;j++){
			cin>>p;
			que.push(p);
		}
		int sum=0;
		int size=que.size();
		for(int i=0;i<size;i++){
			vec.push_back(sum);
			sum+=que.top();
			que.pop();
		}
		int ans=0;
		int vsize=vec.size();
		for(int i=0;i<vsize;i++){
			ans+=vec[i];
		}
		while(!vec.empty())vec.pop_back();
		cout<<ans<<endl;
	}
	return 0;
}