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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define eb emplace_back
#define ssize(v) (int)(v.size())

constexpr int MAX_N=5e5+14;
int N, tmpQt[MAX_N],rres;
vector<int> qt;
void Input(){
    int g;
    cin>>N;
    FOR(i,1,N) cin>>g, ++tmpQt[g];
    FOR(i,1,N) if(tmpQt[i]) qt.eb(tmpQt[i]);
    sort(qt.begin(), qt.end(),greater<int>());
}
void Solve(){
    int p=0,q=ssize(qt)-1, cQt;
    while(p<=q){
        // cout<<"p:"<<p<<" q:"<<q<<" rres:"<<rres<<"\n";
        ++rres;
        cQt=qt[p++]-1;
        while(cQt&&p<=q){
            if(qt[q]==0) {--p; continue;}
            if(qt[q]<=cQt) {cQt-=qt[q--]; continue;}
            qt[q]-=cQt, cQt=0;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    Input();
    Solve();
    cout<<rres;
}