#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))

int n, l[1024];

int solve() {
  sort(l, l + n);
  int ans, cur;
  ans = cur = l[0];
  for (int i = 1; i <= n - 2; ++i) {
    cur += l[i];
    ans += cur;
  }
  return ans;
}

int main() {
  while (cin >> n, n) {
    rep (i,n) cin >> l[i];
    cout << solve() << endl;
  }
  return 0;
}