#include <bits/stdc++.h>
using namespace std;

long long a[int(1e5) + 5];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    long long l = 1, r = n;
    while(l != r) {
        long long m = (l + r) / 2;
        bool check = true;
        for(int i = 0; i < n - m; i++) {
            if(a[i] > m || a[i] == a[n-m]) {check = false; break;}
        }
        if(check) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    long long pred = 0;
    long long minus = 0;
    long long pred_min;
    long long ans = 0;
    for(int i = n-1; i > n - 1 - l; i--) {
        if(a[i] != pred) {
            pred_min = a[i] - minus;
            pred = a[i];
            ans += 1LL * pred_min;
        } else {
            ans += 1LL * pred_min;
        }
        minus++;
        //cout << ans << ' ';
    }
    cout << ans;
}
