#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>

using namespace std;

void Solution()
{
    int n;
    
    while (cin>>n, n)
    {
        vector<int> waitingTime(n);
        
        for (int i = 0; i < n; i++)
        {
            cin >> waitingTime[i];
        }
        
        sort(waitingTime.begin(), waitingTime.end());
        
        long long sum = 0;
        long long ans = 0;
        
        for (int i = 0; i < n; i++)  // 1 + 1+2 + 1+2+3 + 1+2+3+4
        {
            ans += sum;
            sum += waitingTime[i];
        }
        
        cout<<ans<<endl;
    }
}

int main()
{
    Solution();
    return 0;
}