#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    long long int t;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<long long int> deq;
            for (int i=0;i<n;i++) {
                cin>>t;
                deq.emplace_back(t);
            }
            sort(deq.begin(),deq.end());
            std::deque<long long int> S(n+1,0);
            for (int i=0;i<n;i++) {
                S[i+1]=S[i]+deq[i];
            }
            long long int sum=0;
            for (int i=0;i<n;i++) {
                sum+=S[i];
            }
            cout<<sum<<endl;
        }
    }
}
