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
#include <functional>
#include <iostream>
#include <deque>
#include <algorithm>
#define nl '\n'

using namespace std;

int n, res = 0;

int mapper[500001];

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for(int i=0; i<n; i++){
		int val;
		cin>>val;
		mapper[val]++;
	}
	deque<int> q;
	for(int i=1; i<=500000; i++){
		if(!mapper[i]) continue;
		q.push_front(mapper[i]);
	}
	sort(q.begin(), q.end(), greater<int>());
	while(q.size()){
		res++;
		int target = q.front();
		q.pop_front();
		target--;
		while (q.size() && target) {
			int minval = q.back();
			if(target < minval){
				q.back() -= target;
				target -= target;
			}
			else{
				target -= minval;
				q.pop_back();
			}
		}
	}
	cout<<res<<nl;
	return 0;
}