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
54
//
// Jan Zachar 12/03/2024
// Liderzy [B, dz. 1]
//
#include <iostream>
#include <map>
#include <set>
using namespace std;

int n, a;
map<int, int> A;
multiset<int> S;

int main()
{
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

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

	for (auto &u: A) S.insert(u.second);
	//for (auto &u: S) cout << u << ' ';
	//cout << '\n';

	int out = 0;
	while (!S.empty()) {
		int lead = *prev(S.end());
		S.erase(prev(S.end()));

		out++;

		int tot = 0;
		while (tot != lead && !S.empty()) {
			auto u = *S.begin();
			if (u == lead) break;
			S.erase(S.begin());

			if (tot+u <= lead) {
				tot += u;
			} else /*if (tot+u > lead)*/ {
				S.insert(u-lead+tot);
				tot = lead;
			}
		}
	}

	cout << out << '\n';
	return 0;
}