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

using namespace std;

vector<int> count_sort(vector<int> v) {
	vector<int> count(v.size() + 1);
	vector<int> o(v.size());

	for (int i = 0; i < v.size(); i++) {
		count[v[i]]++;
	}
	int i = 0;
	for (int number = v.size(); number >= 1; number--) {
		for (int j = 0; j < count[number]; j++) {
			o[i] = number;
			i++;
		}
	}

	return o;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, input;
	cin >> n;
	vector<int> count(n + 1);

	for (int i = 0; i < n; i++) {
		cin >> input;
		count[input]++;
	}

	vector<int> o = count_sort(count);

	int i = 0, left = n, splits = 0;

	while (left > 0) {
		left -= 2 * o[i] - 1;
		splits++;
		i++;
	}

	cout << splits;
}