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
#include <iostream>
#include <algorithm>
using namespace std;
const int mx = 5e5+5;

int n, x;
int counter[mx];

int main(){
    ios::sync_with_stdio(false);

    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >>x;
        ++ counter[x];
    }

    sort(counter+1, counter+n+1);

    int ans = 0;
    int left = 1;
    int right = n;

    while(left <= right){
        ++ans;
        if(left == right)
            break;

        int total = counter[right];

        while(left < right){
            int actual = counter[left];

            if(total > actual){
                total -= actual;
                ++left;
            }
            else{
                counter[left] -= (total-1);
                break;
            }
        }
        -- right;
    }
    cout << ans;

    return 0;
}