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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int n;
int t[500001];
vector<int> v;

void solve() {
    for(int i =0;i<=n;i++) {
        if(t[i]>0)
            v.push_back(t[i]);
    }
    sort(v.begin(), v.end());


    int s = v.size()-1;
    int e = 0;

    //cout<<"s: "<<s<<"\n";

    int w = 0;
    int ile = 0;
    while(s>e) {
        //if(v[s]>w) {
            int x = min(v[e],v[s]-w-1);
            w += x;
            if(v[e]==x){
                v[e] = 0;
                e++;
            } else {
                v[e]-=x;
                ile++;
                w = 0;
                s--;
            }
      //  }
    }
    if(v[e]!=0)ile++;
    cout<<ile<<"\n";
}

int main()
{

    cin.tie(0)->sync_with_stdio(0);
  
    cin>>n;
    for(int i = 0; i<n;i++) {
        int c;
        cin>>c;
        t[c]++;
    }
    solve();
    return 0;

}