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

int main(){

  int b[10000] = {0},n,z = 0;
  vector < int > a;
 
  cin >> n;

  while(cin >> n, n) a.push_back(n);

  sort(a.begin(),a.end());

  for(int i=1;i<a.size();i++){
    z += a[i-1];
    b[i] = z;
  }

  for(int i=1;i<a.size();i++) b[0] += b[i];

  cout << b[0] << endl;

}