#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned ll
#define dbl double

using namespace std;

const int N = 1e5 + 10;
ll a[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n;
    cin >> n;
    ll maxx = 0;
    for (int i = 1; i <= n; ++i)
    {
        ll x;
        cin >> x;
        ++a[x];
        maxx = max(maxx, x);
    }
    ll cur = maxx;
    ll cost = 0;
    while (cur != 0)
    {
        //for (ll i = 1; i <= n; ++i) cout << a[i] << " "; cout << endl;
        while (cur != 0 && a[cur] == 0)
            --cur;
        if (cur == 0)
            break;
        cost += a[cur] * cur;
        if (a[cur] >= cur)
        {
            cout << cost;
            return 0;
        }
        for (ll i = 1; i <= n - a[cur] - 1; ++i)
            a[i] = a[i + a[cur]];
        for (ll i = n - a[cur]; i <= n; ++i)
            a[i] = 0;
    }
    cout << cost;
}
