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

int main(void){
  int n;
  while(cin >> n && n != 0){
    int c;
    vector<int> vc, s;
    for(int i = 0; i < n; i++){
      cin >> c;
      vc.push_back(c);
    }
    sort(vc.begin(), vc.end());
    s.push_back(0);
    for(int i = 1; i < vc.size(); i++){
      int t = vc[i-1] + s[i-1];
      s.push_back(t);
    }
    int sum = 0;
    for(int i = 0; i < s.size(); i++){
      sum += s[i];
    }
    cout << sum << endl;
  }
  return 0;
}