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
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, a, ile[500009], odp, act, l, wyk;
bool vis[500009];
vector <int>  idx;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++){
    	cin>>a;
        ile[a]++;
    }
    for (int i=1; i<=n; i++) if (ile[i]>0) idx.pb(ile[i]);
    sort (idx.begin(), idx.end(), greater<int>());
    l=idx.size()-1;
    for (int i=0; i<idx.size(); i++){
    	act=idx[i]-1;
        if (act==0) odp++;
        else if (act-idx[l]>=0){
            odp++;	
    		while (act-idx[l]>=0){
	    		act-=idx[l];
	    		idx.pop_back();
	    		l=idx.size()-1;
    		}
    	}
    	else if (idx[l]>=act && act-1>=0){
    		wyk=1;
            odp++;	
    		while (act-wyk>=0 && wyk<idx[l]) wyk++;
    		 act-=wyk;
    		 idx[l]-=wyk;
    	}
        else if (idx.size()-1==i) odp++;
    }
    if (odp==0) cout<<"1";
    else cout<<odp;
    return 0;
}