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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 2137
#endif

const int N = 500500;
int n;
int f[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    f[x - 1]++;
  }
  sort(f, f + n, greater());
  while (f[n - 1] == 0) {
    n--;
  }
  assert(n > 0);
  int lo = 1;
  int hi = n;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    int d = 0;
    int j = n - 1;
    for (int i = 0; i < mid; i++) {
      int s = 0;
      while (j >= mid && s < f[i] - 1) {
        int mx = f[i] - 1 - s;
        if (f[j] - d <= mx) {
          s += f[j] - d;
          j--;
          d = 0;
        } else {
          s += mx;
          d += mx;
        }
      }
    }
    if (j == mid - 1) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  cout << lo << '\n';
}