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
#include <iostream>
#include <ranges>
#include <unordered_map>
#include <map>

using namespace std;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    uint32_t n;
    cin >> n;

    unordered_map<uint32_t, uint32_t> counts;
    map<uint32_t, uint32_t> counts_count;
    uint32_t temp;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        counts[temp]++;
    }

    for (auto [num,count]: counts) {
        counts_count[count]++;
    }
    uint32_t count_seq = 0;
    uint32_t num_in;
    for (auto [count, count_num] : std::ranges::reverse_view(counts_count)) {
        num_in = (n - 1) / (count * 2 - 1) + 1;
        if (num_in <= count_num) {
            count_seq += num_in;
            cout << count_seq << '\n';
            return 0;
        } else {
            n -= (count * 2 - 1) * count_num;
            count_seq += count_num;
        }
    }
    return 0;
}