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
#include<bits/stdc++.h>
using namespace std;
unordered_map<int, int> tab1;
multiset<int, greater<int>> tab2;
int n, a, x, y, z, ans;
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        tab1[a]++;
    }
    for (pair<int, int> item : tab1) {
        tab2.insert(item.second);
    }
    while (int(tab2.size()) > 1) {
        x = *tab2.begin();
        tab2.erase(tab2.find(x));
        y = *tab2.begin();
        tab2.erase(tab2.find(x));
        x--;
        while (tab2.lower_bound(x) != tab2.end()) {
            z = *tab2.lower_bound(x);
            tab2.erase(tab2.find(z));
            x -= z;
        }
        tab2.insert(y);
        ans++;
    }
    if (!tab2.empty()) {
        ans++;
    }
    cout << ans << endl;
    return 0;
}