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
// Autor: Nicolas Wochnik
#include <algorithm>
#include <iostream>
#include <vector>

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

  size_t arr_size;
  std::cin >> arr_size;

  std::vector<int> arr(arr_size);

  for (size_t i = 0; i < arr.size(); ++i) {
    std::cin >> arr[i];
  }

  std::sort(arr.begin(), arr.end());

  std::vector<int> repeats;
  int repeat = 1;

  for (size_t i = 1; i < arr.size(); ++i) {
    if (arr[i - 1] != arr[i]) {
      repeats.push_back(repeat);
      repeat = 0;
    }

    repeat++;
  }

  repeats.push_back(repeat);
  std::sort(repeats.begin(), repeats.end());

  int left = 0, right = repeats.size() - 1;
  int answer = 0;

  while (left <= right) {
    repeats[right]--;

    while (repeats[right] > 0) {
      int decrement = std::min(repeats[right], repeats[left]);

      repeats[right] -= decrement;
      repeats[left] -= decrement;

      if (repeats[left] == 0) {
        left++;
      }
    }

    answer++;
    right--;
  }

  std::cout << answer << "\n";

  return 0;
}