1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int run() {
    int n;
    cin >> n;
    vector<int> occs(n);
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        occs[p - 1]++;
    }
    sort(occs.begin(), occs.end());

    int res = 0;
    int l = 0, r = n - 1;
    while (l <= r) {
        res++;
        occs[r]--;
        while (l < r && occs[l] <= occs[r]) {
            occs[r] -= occs[l];
            occs[l] = 0;
            l++;
        }
        if (l < r) {
            occs[l] -= occs[r];
        }
        r--;
    }

    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << run();
}