#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n;
  while(true){
  cin >> n;
  if(n == 0)break;
  vector<int> vec;
  rep(i,n){
    int val;
    cin >> val;
    vec.pb(val);
  }
  if(n == 1){
    cout << 0 << endl;
    continue;
  }
  sort(all(vec));
  int sum[n+2];
  ll total = vec[0];
  sum[1] = vec[0];
  for(int i=2;i<n;i++){
    sum[i] = sum[i-1]+vec[i-1];
    total += sum[i];
  }
  cout << total << endl;
  }
return 0;
}