#include<iostream>
using namespace std;

void merge( int* A, int left, int mid, int right )
{
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1], R[n2+1];

    for( int i = 0; i <= n1 - 1; i++ )
        L[i] = A[left + i];
    for( int i = 0; i <= n2 - 1; i++ )
        R[i] = A[mid + i];

    L[n1] = 2000000000;
    R[n2] = 2000000000;

    int i = 0, j = 0;
    for( int k = left; k <= right - 1; k++ )
    {
        if( L[i] <= R[j] )
        {
            A[k] = L[i];
            i = i + 1;
        }
        else 
        {
            A[k] = R[j];
            j = j + 1 ;
        }
    }
}

void mergeSort( int* A, int left, int right )
{
    if( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        mergeSort( A, left, mid );
        mergeSort( A, mid, right );
        merge( A, left, mid, right );
    }
}

int main()
{
    int n;

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

        int a[n];
        for( int i = 0; i < n; i++ )
            cin >> a[i];

        mergeSort( a, 0, n );

        int sum = 0, sum2 = 0;
        for( int i = 0; i < n - 1; i++ )
        {
            sum += a[i];
            sum2 += sum;
        }
        cout << sum2 << endl;
    }

    return 0;
}
