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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;

typedef vector<char> VC;
typedef vector<vector<char>> VVC;
typedef vector<bool> VB;
typedef vector<vector<bool>> VVB;

typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<pair<int, int>> VPI;
typedef vector<pair<long long, long long>> VPL;

#define LINE '\n'
#define SPACE ' '
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()


void solve()
{
    int n;
    cin >> n;

    map<int, int> mp;
    FOR(i, 0, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    VI vec;
    for(auto &[key, val] : mp) vec.PB(val);
    sort(RALL(vec));


    int p = vec.size() - 1;
    int ans = 0;
    for(int i = 0; i < p; i++) {
  
        int ct = 0;
        int limit = vec[i] - 1;
        while(i < p && ct < limit) {
            if(vec[p] + ct < limit) {

                ct += vec[p];
                vec[p] = 0;
                p--;
            }
            else {
                int del = min(limit - ct, vec[p]);
    
                ct += del;
                vec[p] -= del;
                if(vec[p] == 0)p--;

                break;
            }
        }

        vec[i] = 0;
        ans++;
    }

    if(vec[p] != 0) ans++;
    cout << ans << LINE;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;

    while (t--)
        solve();
}