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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> tab(n + 1);
    int x;
    for(int i = 0; i < n; i++){
        cin >> x;
        tab[x]++;
    }

    sort(tab.begin(), tab.end(), std::greater<>());
    int i = 0;
    int j = n;
    int y = 0;
    int counter = 0;
    while(i < j){
        while(i < j && tab[j] < tab[i]){
            tab[i] = tab[i] - tab[j];
            j--;
        }
        if(tab[i] != 1 && i != j){
            tab[j] = tab[j] - tab[i] + 1;
        }
        if(i == j){
            break;
        }
        i++;
    }

    cout << i + 1 << '\n';

    return 0;
}