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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<int> A;
	unordered_map<int, int> place;
	int n;
	cin >> n;
	int no_numbers = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		std::cin >> a;
		if (place.find(a) == place.end()) {
			place.insert({ a,no_numbers });
			A.push_back(1);
			no_numbers++;
		}
		else {
			A[place[a]]++;
		}
	}
	sort(A.begin(), A.end(), greater<int>());
	int i = 0;
	while (A[i] <= n/2)
	{
		n -= (A[i] * 2) - 1;
		i++;
	}
	cout << i + 1;
}