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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      priority_queue<int, vector<int>, greater<int> > qu;
      for(;n--;)
	{
	  int t;
	  cin>>t;
	  qu.push(t);
	}
      int sum=0,tmp=0;
      for(;!qu.empty();)
	{
	  sum+=tmp;
	  tmp+=qu.top();
	  qu.pop();
	}
      cout<<sum<<endl;
    }
}