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<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
#define all(a) a.begin(), a.end()
#define print(a) for (auto elem:a) cout<<elem<<' '; cout<<'\n'
#define segprep(b) resize(1<<((int)ceil(log2(b.size()))+1))

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    vi nums(n);
    for (auto &i:nums) cin>>i;
    vi cnt(n+1, 0);
    for (auto &i:nums) cnt.at(i)++;

    deque<int> counts; //occ, num
    for (int i = 1; i <= n; i++){
        if (cnt.at(i)) counts.push_back(cnt.at(i));
    }

    sort(all(counts), greater<int>());

    int ans = 0;
    while (!counts.empty()){
        auto curr = counts.front();
        ans++;
        counts.pop_front();
        if (counts.empty()) break;
        int smol_sum = 0;
        while(!counts.empty() && smol_sum+counts.back() < curr){
            smol_sum += counts.back();
            counts.pop_back();
        }
        if (!counts.empty()) counts.back() -= curr-smol_sum-1;
    }

    cout<<ans<<'\n';
}