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
42
43
44
45
46
47
48
49
50
51
52
53
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

typedef long long ll;
typedef long double ld;
const int maxN = 5e5 + 10;
int n;
int cnt[maxN];
int a[maxN];
mt19937 rnd(228);
void solve() {
    cin >> n;
    vector<pair<int,int>> s;
    for (int i = 1; i <= n; i++) {
        cnt[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        s.emplace_back(cnt[i], i);
    }
    sort(s.rbegin(), s.rend());
    int L = 0;
    for (int z = 0; z < s.size(); z++) {
        L += 2 * s[z].first - 1;
        if (L >= n) {
            cout << z + 1 << endl;
            return;
        }
    }
    assert(false);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst = 1;
//    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}