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
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin>>n;
	vector<int>cnt(n+1);
	for (int i=0; i<n; i++)
	{
		int x; cin>>x;
		cnt[x]++;
	}
	vector<int>a;
	for (auto i : cnt) if (i) a.push_back(i);
	sort(a.begin(), a.end(), greater<int>());
	int ans=1, p=0, k=a.size()-1;
	while (p<k)
	{
		a[p]--;
		while (a[k] <= a[p] && p < k) a[p]-=a[k], k--;
		if (k == p) break;
		a[k]-=a[p];
		if (a[k] == 0) k--;
		if (k == p) break;
		ans++, p++;
	}
	cout<<ans<<"\n";
}