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
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;
using ll = long long;

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

	int n;
	cin >> n;
	vector<int> v(n);
	unordered_map<int, int> cnt;
	for (auto &i : v) {
		cin >> i;
		cnt[i]++;
	}

	sort(v.begin(), v.end(), [&cnt](int a, int b) {
		return cnt[a] > cnt[b] || (cnt[a] == cnt[b] && a < b);
	});

	int res = 0;
	int leader = v[0] - 1;
	for (int i = 0; i < v.size(); i++) {
		if (v[i] != leader) {
			res++;
			leader = v[i];
		} else {
			v.pop_back();
		}
	}
	cout << res << '\n';
}