#include<bits/stdc++.h>
#include<stdlib.h>
using namespace std;
 
const int MAXN=1000001;
int cnt[MAXN]={};
queue<long> orgQ, addQ;
inline long LeastNumber(long rem=0){
  if(orgQ.empty() or addQ.empty()==0 and addQ.front()<orgQ.front())
    rem=addQ.front(), addQ.pop();
  else
    rem=orgQ.front(), orgQ.pop();
  return rem;
}

char buf[1 << 23];

int main(){

  int N, x;

  while(scanf("%d\n",&N) != EOF and N){
    // init
    memset(cnt,0,sizeof(cnt));
    while(orgQ.empty()==0) orgQ.pop();
    while(addQ.empty()==0) addQ.pop();

    // CountSort
    
    x = 0;
    for(char *p = fgets(buf,sizeof(buf),stdin); *p != '\n'; ++p){
       if(*p == ' '){
          cnt[x]++;
          x = 0;
          continue;
       }
       x = 10 * x + *p - '0';
    }
    cnt[x]++;

   for(int i=1;i<MAXN;i++)
      for(int j=0;j<cnt[i];j++)
        orgQ.push(i);
    long sum=0, min_one, min_two;
    for(int t=1; t<N; t++){
      min_one=LeastNumber(),
      min_two=LeastNumber(),
      sum+=min_one+min_two;
      addQ.push(min_one+min_two);
    }
    printf("%ld\n",sum);
  }
}