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
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    
    cin >> n;
    
    vector<int> cnt(n + 1);
    
    vector<int> cnt2(n + 1);
    
    int e;
    
    int h;
    
    int j;
    
    int r;
    
    for (int i = 0; i < n; i++){
        cin >> e;
        cnt[e]++;
    }
    
    for (int i = 0; i < n; i++){
        cnt2[cnt[i]]++;
    }
    
    for (int i = n - 1; i >= 0; i--){
        for (int k = 0; k < cnt2[i]; k++){
            h = (i - 1);
            j = 0;
            while (h > 0 && j < i){
                if (cnt2[j] * j > h){
                    cnt2[j] -= (h + j - 1) / j;
                    r = h % j;
                    cnt2[r]++;
                    h = 0;
                }else{
                    h -= cnt2[j] * j;
                    cnt2[j] = 0;
                }
                j++;
            }
        }
    }
    int res = 0;
    
    for (int i = 1; i < n; i++){
        res += cnt2[i];
    }
    
    cout << res;
    
    return 0;
}