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
//Jakub Nowak XIV LO Wroclaw
#include<bits/stdc++.h>
using namespace std;

#define boost ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define vi vector<int>
#define pb push_back
#define st first
#define nd second

/*void wypisz(auto &X) {
    for(auto &x : X) cout << x << " ";
    cout << "\n";
}*/

void solve() {
    int n;
    int ans = 0;
    vi ILE;
    vi ILE2;

    cin >> n;
    ILE = vi(n+1, 0);
    ILE2 = vi(n+1, 0);
    for(int i=1; i<=n; i++) {
        int x;
        cin >> x;
        ILE[x]++;
    }

    //wypisz(ILE);

    for(int i=1; i<=n; i++) {
        ILE2[ILE[i]]++;
    }

    //wypisz(ILE2);

    int ile_mozna = 0;
    for(int i=n; i>=0; i--) {
        while(ile_mozna < n && ILE2[i]) {
            ile_mozna += 2*i-1;
            ILE2[i]--;
            ans++;
        }
    }

    //wypisz(ILE2);

    cout << ans << "\n";
}

int32_t main() {
    boost
    solve();
}