#include <bits/stdc++.h>
using namespace std;
const long long N = 100100;
long long a[N];
map <long long,long long> cnt2;

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

	int n;
	cin>>n;
    for (long long i = 1 ;i<=n;i++)
    {
        cin >> a[i];
    }
    sort (a,a+N);
    long long cnt = 0;
    long long ans = 0;
    long long last = a[N-1];
    for (long long i = N-1;i>=0;i--)
    {
        if (a[i] - cnt + cnt2[a[i]] > 0)
        {
            cnt++;
            cnt2[a[i]]++;
            ans += a[i] - cnt + cnt2[a[i]];
        }
    }
    cout << ans;
}
