#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main()
{
    lol n, o=0;
    map<lol, lol> mp;
    cin>>n;
    set<lol> st;
    for (lol i=0;i<n;i++)
    {
        lol a;
        cin>>a;
        mp[a]++;
    }
    vector<pair<lol, lol> > v;
    for (auto it=mp.begin();it!=mp.end();it++)
    {
        v.push_back({it->first, it->second});
    }
    sort(v.begin(), v.end());
    lol ans=0, k=0;
    for (lol i=v.size()-1;i>=0;i--)
    {
        ans+=max(o, v[i].second*(v[i].first-k));
        k+=v[i].second;
    }
    cout<<ans;
}
