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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "stdio.h"
#include <vector>

using namespace std;

int numbers_to_counts[500003];
int counts_counts[500003];

int main(){
    int n, tmp, max_leader = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; i++){
        scanf("%d", &tmp);
        numbers_to_counts[tmp]++;

        if (numbers_to_counts[tmp] > max_leader){
            max_leader = numbers_to_counts[tmp];
        }
    }

    for (int i = n; i > 0; i--){
        if (numbers_to_counts[i] > 0) {
            counts_counts[numbers_to_counts[i]]++;
        }
    }

    std::vector<int> counts( 0);
    counts.reserve(n);

    for (int i = 1; i <= n; i++) {
        if (counts_counts[i] > 0){
            for (int j = 0; j < counts_counts[i]; j++)
                counts.push_back(i);
        }
    }

    int r = counts.size() - 1;
    int l = 0;
    int res = 1;

    while (l < r){
        int capacity = counts[r] - 1;
        while (capacity > 0 && l < r) {
            if (counts[l] <= capacity){
                capacity -= counts[l];
                counts[l] = 0;
                l++;
            }
            else {
                counts[l] -= capacity;
                capacity = 0;
            }
        }
        if (l == r) break;
        r--;
        res++;
    }

    printf("%d\n", res);

    return 0;
}