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
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    vector<int> wartosci;
    map<int, int> ilosci;
    int n, element;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> element;
        ilosci[element]++;
    }

    for (const auto &pary: ilosci) {
        wartosci.push_back(pary.second);
    }
    sort(wartosci.begin(), wartosci.end());

    int ilosc_wartosi = wartosci.size();
    int index_min = 0;
    int index_maks = wartosci.size() - 1;


    while (index_min != index_maks) {
        int ciag_min = wartosci[index_min];
        int ciag_maks = wartosci[index_maks];
        if(ciag_min<=ciag_maks - 1){
            wartosci[index_maks] -= wartosci[index_min];
            index_min++;
            ilosc_wartosi--;
        }
        else{
            wartosci[index_min] -=( wartosci[index_maks] + 1);
            index_maks--;
        }

    }
    cout << ilosc_wartosi;
    return 0;
}