
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp (ll v1, ll v2)
{
    return v1 > v2;
}
int main()
{
    ll n;
    cin >> n;
    vector <ll> v = {};
    for (ll i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end(), cmp);
    ll o = 1000000000;
    ll j = 0;
    ll m = 0;
    ll j1 = 0;
    for (ll i = 0; i < n; i++)
    {
        ll k = 0;
        if (v[i] - j < 2) {k = 0;}
        else {
        k = (((v[i] - j + 3) * (v[i] - j)) / 2);}
        if (k < 0) {k = 0;}
        k += m;
        if (k < o) {o = k;}
        m += (v[i] - j);
        j1++;
        if (i != n - 1 && v[i] != v[i + 1]) {j += j1; j1 = 0;}
        //cout << k << " ";
    }
    cout << o;
}
