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

int main(){
    int n,sum,temp;
    priority_queue<int,vector<int>,greater<int>> que;

    while(cin>>n,n){
        sum=0;
        temp=0;
        for(int i=0;i<n;i++){
            int t;
            cin>>t;
            que.push(t);
        }

        while(que.size()>1){
            sum+=(temp+que.top());
            temp+=que.top();
            que.pop();
        }
        que.pop();

        cout<<sum<<endl;
    }

    return 0;
}