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
# include <bits/stdc++.h>
# define For(i, l, r) for(int i = (l); i <= (r); i++)
# define Rep(i, n) For(i, 0, (n) - 1)
# define size(x) (ll)x.size()
# define MAXSZ 500005
# define all(x) x.begin(),x.end()
using namespace std;
typedef int ll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
ll n , m , q , r , k , t , L , R;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vector<ll>vec(n) , cnt(n);
    Rep (i , n) {
        cin >> vec[i];
        vec[i]--;
        cnt[vec[i]]++;
    }
    sort(cnt.rbegin() , cnt.rend());
    auto check = [&](ll kol) -> bool {
        ll can = 0;
        Rep (i , kol) {
            can += (2 * cnt[i] - 1);
        }
        if (can >= n) return 1;
        else return 0;
    };
    ll l = 0 , r = n;
    while (r - l != 1) {
        ll mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid;
    }
    cout << r;
}
//odjgoadfhfoav hash1 i hash2 (hash1 * 1e9 + hash