#include <bits/stdc++.h>
            using namespace std;
            #define bust ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
            #define fr first
            #define sd second
            #define X real()
            #define Y imag()
            #define pb push_back
            typedef long long ll;
            typedef unsigned long long ull;
            typedef long double ld;
            #define FOR(i, a, b) for (int i = a; i < (b); ++i)
            #define F0R(i, b) for (int i = 0; i < (b); ++i)
            #define F1R(i, b) for (int i = 1; i < (b); ++i)
            #define FORd(i, a, b) for (int i = (b) - 1 ; i >= a; --i)
            #define F0Rd(i, b) for (int i = (b) - 1; i >= 0; --i)
            #define FORll(i, a, b) for (ll i = a; i < (b); ++i)
            #define F0Rll(i, b) for (ll i = 0; i < (b); ++i)
            #define F1Rll(i, b) for (ll i = 1; i < (b); ++i)
            #define FORdll(i, a, b) for (ll i = (b) - 1 ; i >= a; --i)
            #define F0Rdll(i, b) for (ll i = (b) - 1; i >= 0; --i)
            #define pr(qw) cout << (qw) << '\n'
            #define el pr('\n')
            #define pr2(s, q) cout << (s) << ' ' << (q) << '\n'
            #define ret return
            typedef pair<int, int> pii;
            typedef pair<long long, long long> pll;
            typedef complex<ll> C;
            main(){
                int n;
                cin >> n;
                ll a[n], s = 0, c = 0, res = 0;
                F0R(i, n) {cin >> a[i]; s+= a[i];}
                sort(a, a+n);
                reverse(a, a+n);
                int curr = 0;
                F0R(i, n){
                    int fl = 0;
                    curr++;
                    if(i>=1){ if(a[i]==a[i-1]) {a[i]+=curr - 1; fl=1;} else curr = 1;}
                    if(c > a[i]) break;
                    res += a[i] - c;
                    c++;
                    if(fl==1) a[i]-= (curr-1);

                }
                pr(res);










            }
