#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        vector<unsigned>vec,v;
        while(n--){
            unsigned t;
            cin>>t;
            vec.push_back(t);
        }
        sort(vec.begin(),vec.end());
        unsigned tot=0;
        unsigned ans=0;
        for(int i=1;i<vec.size();i++){
            ans+=tot;
            tot+=vec[i-1];
        }
        
        cout<<ans<<endl;
    }
}