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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define st first
#define nd second

const int N = 5e5 + 5;
int counter[N];
int counts[N];

void TEST([[maybe_unused]] int testcase_i) {
  int n;
  cin >> n;

  rep(i, n) {
    int x;
    cin >> x;
    counter[x]++;
  }

  rep(i, N) {
    counts[counter[i]]++;
  }

  vector<int> v;
  for (int i = N - 1; i > 0; i--) {
    while (counts[i]) {
      v.push_back(i);
      counts[i]--;
    }
  }

  int ans = 0;
  int start = 0;
  while (start < (int)v.size()) {
    int cur = v[start] - 1;
    ans++;
    while (cur > 0) {
      if (v.back() > cur) {
        v.back() -= cur;
        cur = 0;
      } else {
        cur -= v.back();
        v.pop_back();
      }
    }
    start++;
  }

  cout << ans;
}

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

  cout << setprecision(20) << fixed;

  // srand(time(NULL));

  int t = 1;
  // cin >> t;
  rep(i, t) {
    TEST(i);
  }

  return 0;
}