#include<iostream>
using namespace std;

void bubbleSort( int* a, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= 1 + i; j-- )
            if( a[j] < a[j-1] )
            {
                int temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
}

int main()
{
    int n, a[100], b[100];;

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

        for( int i = 0; i < 100; i++ )
        {
            a[i] = 0;
            b[i] = 0;
        }
    
        for( int i = 0; i < n; i++ )
            cin >> a[i];
        
        bubbleSort( a, n );

        b[0] = a[0];
        for( int i = 1; i < n; i++ )
            b[i] = b[i-1] + a[i];

        int sum = 0;
        for( int i = 0; i < n; i++ )
            sum += b[i];
        
        cout << sum << endl;
        
    }
    return 0;

}
