#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    sort(a.begin(), a.end());
    ll res = 0;
    int offset = 0, h=n-1;
    while(a[h]-offset > 0 && h>=0){
        int toff = 1;
        res+=a[h]-offset;
        h--;
        while(h>=0 && a[h] == a[h+1]){
            res+=a[h]-offset;
            toff++;
            h--;
        }
        offset += toff;
    }
    cout<<res;
}
