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

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

  int n;
  std::cin >> n;

  std::vector<int> cnt(n, 0);

  for (int i = 1; i <= n; i++) {
    int x;
    std::cin >> x;
    cnt[x - 1]++;
  }

  std::sort(cnt.begin(), cnt.end(), std::greater<int>());

  int A, B;
  A = B = 0;

  for (int i = 0; i < n; i++) {
    A += cnt[i];
    B += cnt[i] - 1;
    if (A + B >= n) {
      std::cout << i + 1 << "\n";
      return 0;
    }
  }
}