#include <iostream>
using namespace std;

int main(){
  int data[10010];
  while(1){
    int n; cin >> n;
    if( n == 0 ) break;
  
    int i,j;
    for( i = 1; i <= n; i++ )cin >> data[i];
    
    for( i = 1; i <= n; i++ ){
      for( j = 1; j < n; j++ ){
	if( data[j] > data[j+1]) swap( data[j],data[j+1] );
      }
    }
   
    long long time = 0,total = 0;
    
    for( i = 1; i <= n; i++ ){
      // cout << "i" << i << " ";
      total += data[i-1];
      // cout << "total" << total << " " << "data[i-1]" << data[i-1] << " ";
      time += total;
      // cout << "time" << " " << time << endl;
    }
    cout << time  << endl;
  }
  
  return 0;
}