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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int d[500009];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		d[x]++;
	}
	sort(d + 1, d + n + 1, greater<>());
	int j = n;
	while (d[j] == 0) {
		j--;
	}
	int ans = 0;
	for (int i = 1; i <= j; i++) {
		while (d[i] - d[j] > 0) {
			d[i] -= d[j];
			j--;
		}
		d[j] -= d[i] - 1;
		d[i] = 1;
		ans++;
	}
	cout << ans << "\n";
	return 0;
}