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

int main()
{
  int a[10000];
  int n;

  while (1){
    cin >> n;
    if (n == 0){
      break;
    }

    for (int i = 0; i < n; i++){
      cin >> a[i];
    }
    sort(a, a + 5);
    for (int i = 0; i < n; i++){
      a[i + 1] += a[i];
    }

    for (int i = 0; i < n; i++){
      a[i + 1] += a[i];
    }
    /*
    for (int i = 0; i < n; i++){
      cout << a[i] << endl;
    }
    */
    cout << a[n - 2];
  }
  return 0;
}