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
#include <bits/stdc++.h>
using std::cin, std::cout, std::vector;

void init_io() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
}

unsigned solve() {
  unsigned n;
  cin >> n;
  vector<unsigned> counts(n);

  for (unsigned i = 0; i < n; ++i) {
    unsigned x;
    cin >> x;
    --x;
    counts[x] += 1;
  }

  vector<unsigned> multiplicies(n+1, 0);
  for (const unsigned c : counts) multiplicies[c] += 1;

  unsigned done = 0;
  unsigned groups = 0;
  for (unsigned c = n; c > 0; --c) {
    const unsigned m = multiplicies[c];
    for (unsigned i = 0; i < m; ++i) {
      done += 2 * c - 1;
      ++groups;
      if (done >= n) {
        return groups;
      }
    }
  }
  throw 0;
}

int main() {
  init_io();
  cout << solve() << "\n";
}