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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int limit = 1e6;
int ile[limit];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    int n, a;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        ile[a]++;
    }
    vector<int> q;
    for(int i = 1; i <= n; i++){
        if(ile[i] > 0) q.push_back(ile[i]);
    }
    sort(q.begin(), q.end());
    int w = 1, l = 0, p = q.size() - 1, s = n, akt;
    while(2 * q[p] <= s){
        akt = 1;
        while(akt < q[p] && l < p){
            akt++;
            q[l]--;
            s--;
            if(q[l] == 0) l++;
        }
        s -= q[p];
        p--;
        w++;
    }
    cout << w << "\n";
    return 0;
}