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;

int n, x, p = 0, wynik;
int t[500001];
vector <int> v;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        t[x]++;
    }
    for (int i = 1; i <= n; i++) {
        if (t[i] == 0) continue;
        v.push_back(t[i]);
    }
    sort(v.begin(), v.end());
    for (int i = v.size() - 1; i >= 0; i--) {
        if (v[i] > 0) {
            v[i]--;
            wynik++;
        }
        while (v[i] > 0) {
            if (v[p] <= v[i]) {
                v[i] -= v[p];
                v[p] = 0;
                p++;
            }
            else {
                v[p] -= v[i];
                v[i] = 0;
            }
        }
    }
    cout << wynik << "\n";
}