#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pi 3.14159265358979323846
#define sqr(a) (a)*(a)
#define v vector
#define ll long long
#define ld long double
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define umap unordered_map
#define sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define mod 1000000007
#define inf 2*1e18

using namespace std;
using namespace __gnu_pbds;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>uset;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    ll n,i,ans=0,now=0;
    cin>>n;
    v<ll>a(n);
    map<ll,ll>mp;
    for (i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a);
    rev(a);
    for (i=0;i<n;i++){
        ans+=max(0ll,a[i]-now+mp[a[i]]);
        mp[a[i]]++;
        now++;
    }
    cout<<ans;
    return 0;
}
