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
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	long long n;
	cin >> n;
	vector<long long>v(n);
	map<long long,long long>mp;
	for(auto&i:v){
		cin>>i;
		mp[i]++;
	}
	vector<long long>a;
	for(auto&i:mp){
		a.push_back(i.second);
	}
	sort(a.begin(),a.end());
	deque<long long>dq;
	while(a.size()){
		dq.push_back(a[a.size()-1]);
		a.pop_back();
	}
	//for(auto&i:dq){cout<<i<<" ";}
	//cout<<endl;
	long long o=0;
	while(dq.size()){
		if(dq.size()==1){
			o++;
			//cout<<"k"<<dq[0]<<endl;
			dq.pop_front();
			continue;
		}
		o++;
		long long b=dq.front();
		//cout<<b<<"   ";
		//for(auto&i:dq){cout<<i<<" ";}
		//cout<<"   ";
		dq.pop_front();
		while(dq.size() && b>dq.back()){
			b-=dq.back();
			dq.pop_back();
		}
		if(dq.size()){dq.back()-=(b-1);}
		//for(auto&i:dq){cout<<i<<" ";}
		//cout<<endl;
	}
	cout<<o<<endl;
}