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
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int get_result(int n, vector<int> a) {
  vector<int> counts(n + 1);

  fill(counts.begin(), counts.end(), 0);

  for (int a_i : a) {
    counts[a_i]++;
  }

  sort(counts.begin(), counts.end(), greater<int>());

  for (int size = 0, i = 0; i < counts.size(); i++) {
    size += counts[i] * 2 - 1;

    if (size >= n) {
      return i + 1;
    }
  }

  return -1;
}

int main() {
  int n;

  scanf("%d", &n);

  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  printf("%d\n", get_result(n, a));
}