#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<int, int> boxes;
    for (int i = 0; i < n; i++) {
        if (boxes.find(a[i]) != boxes.end()) {
            boxes[a[i]] += 1;
        } else {
            boxes[a[i]] = 1;
        }
    }
    int c = 0;
    while (boxes.size() > 1) {
        int last = *max_element(boxes.begin(), boxes.end(),
                                [](pair<int, int> a, pair<int, int> b) {
                                    return a.second < b.second;
                                });
        c += last.second;
        map<int, int> tmp = boxes;
        for (auto it = boxes.begin(); it != boxes.end(); it++) {
            if (it->first > last.first) {
                tmp[it->first + 1] = tmp[it->first];
                tmp[it->first] = 0;
            } else if (it->first < last.first) {
                tmp[it->first - 1] = tmp[it->first];
                tmp[it->first] = 0;
            }
        }
        for (auto it = boxes.begin(); it != boxes.end(); it++) {
            if (it->first > last.first) {
                tmp[it->first] = tmp[it->first - 1];
                tmp[it->first - 1] = 0;
            } else if (it->first < last.first) {
                tmp[it->first] = tmp[it->first + 1];
                tmp[it->first + 1] = 0;
            }
        }
        tmp[last.first] -= 1;
        if (tmp[last.first] == 0) {
            tmp.erase(last.first);
        }
        boxes = tmp;
    }
    cout << c << endl;
}