#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    long long sum = 0;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int number;
        cin >> number;
        if (number > v.size())
            v.resize(number);
        v[number - 1]++;
    }
    int place = v.size() - 1;
    while (n > 0) {
        while(v[place] == 0)
            place--;
        v[place]--;
        sum += place + 1;
        n--;
        if (place > 0)
            n -= v[0];
        for (int i = 0; i < place - 1; i++)
            v[i] = v[i + 1];
        v[place - 1] = 0;
    }    
    cout << sum;
}