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
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator <<(auto& o, pair<auto, auto> p) {return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";}
#define debug(X) cout<<"["#X"]"<<X<<endl;
#else
#define debug(X) {}
#endif
#define int long long
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<int> tab(n);
	for(auto& v : tab) cin>>v;
	sort(tab.begin(), tab.end());
	vector<int> grp;
	int k = 1;
	for(int i=1;i<tab.size();i++)
	{
		if(tab[i] != tab[i-1]) {grp.push_back(k); k = 0;}
		k++;
	}
	grp.push_back(k);
	sort(grp.begin(), grp.end());
	reverse(grp.begin(), grp.end());
	debug(grp);
	int sum = 0;
	for(int i=0;i<grp.size();i++)
	{
		sum += (grp[i]*2)-1;
		debug(sum);
		if(sum >= n) {cout<<i+1; break;}
	}
}