#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
typedef long long ll;

const int nmax=200010;

tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ost;

int mas[nmax]={0};
int dp[nmax][2]={0};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,cur=0;
    ll ans=0;
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> mas[i];
    }
    sort(mas,mas+n);
    for(int i=n-2;i>=0;i--) {
        dp[i][1]=dp[i+1][1]+1;
        dp[i][0]=dp[i+1][0];
        if(mas[i]!=mas[i+1]) {
            dp[i][0]=dp[i][1];
        }
    }
    for(int i=n-1;i>=0;i--) {
        ans+=max(0,mas[i]-dp[i][0]);
    }
    cout << ans << "\n";
    return 0;
}
