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 <algorithm>
#include <iostream>
#include <vector>

void solve() {
    int n;
    std::cin >> n;
    std::vector<int> cnt(n+1);
    for (int i = 0; i < n; i++) {
        int x;
        std::cin >> x;
        cnt[x]++;
    }

    std::sort(cnt.begin(), cnt.end(), std::greater<int>());
    int all = 0;
    for (auto x : cnt) all += x;

    int i = 0;
    int sum = cnt[0];
    while (sum - i - 1 < all - sum) sum += cnt[++i];
    std::cout << i+1 << '\n';
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);

    solve();

    return 0;
}