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
62
63
64
65
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int a[500100];
int ile[500100];

bool rob(vector<int> &wektor, int &index) {
    int usuwane = wektor[index]-1;
    //cout<<"Aktualnie "<<index<<endl;
    //cout<<"Stan wektora to: ";
    //for (int w : wektor) cout<<w<<" ";
    //cout<<endl<<endl;
    
    index++;
    
    while(wektor.size() != index && usuwane > 0) {
        if (wektor[wektor.size()-1] >= usuwane) {
            wektor[wektor.size()-1] -= usuwane;
            usuwane = 0;
            
            if(wektor[wektor.size()-1] == 0)
                wektor.pop_back();
        }
        else {
            usuwane -= wektor[wektor.size()-1];
            wektor.pop_back();
        }
    }
    
    
    if(wektor.size() == index) return false;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>a[i];
        ile[a[i]]++;
    }
    
    vector<int> wektor;
    for(int i=1;i<=n;i++)
        if (ile[i] > 0) wektor.push_back(ile[i]);
    sort(wektor.begin(), wektor.end(), greater<int>());
    
    int result = 1;
    int index = 0;
    while(true) {
        if(!rob(wektor, index)) break;
        result++;
    }
    
    cout<<result<<endl;

    return 0;
}