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
#include <bits/stdc++.h>
using namespace std;

int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int n;
    cin >> n;

    vector<int> lider_cnt(n + 1, 0);
    vector<int> cnt_cnt(n + 1, 0);

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

    for (int i = 1; i <= n; i++) {
        cnt_cnt[lider_cnt[i]]++;
    }

    int wynik = 0;
    int remaining = n;
    for (int i = n; i > 0 && remaining > 0; i--) {
        while (cnt_cnt[i] && remaining > 0) {
            remaining -= (2 * i - 1);
            cnt_cnt[i]--;
            wynik++;
        }
    }

    cout << wynik << "\n";
}