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

int boxes[100000];
int mapi[1000];
int um[1000] = {-1};

int main(){
    int n;
    int uml=0;
    long long br=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>boxes[i];
        mapi[boxes[i]]++;
    }
    sort(boxes, boxes+n/*, greater<int>()*/);
    //333446

    for(int i =0; i<n; i++){
        if(um[uml]==-1){
            um[uml]=boxes[i];

        }
        if(um[uml]!=(-1) and um[uml]!=boxes[i]){
            uml++;
            um[uml]=boxes[i];
        }
    }
    for(int i = 0; i<uml; i++){
        if(abs( mapi[um[i+1]]-mapi[um[i]])==mapi[um[i+1]]-mapi[um[i]]){
            br+=um[i+1]*(mapi[um[i+1]]-mapi[um[i]]);
            //cout<<"1: "<<uml<<' '<<um[i]<<' '<<br<<endl;
        }else{
            br+=um[i]*abs((mapi[um[i+1]]-mapi[um[i]]));
            //cout<<"2: "<<uml<<' '<<boxes[i]<<' '<<um[uml]<<' '<<br<<endl;
        }
    }
    br+=um[uml]*mapi[um[uml]];
    cout<<br;
}
