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
#include <bits/stdc++.h>

using namespace std;

const int N = 300'000 + 7;

int n, ile[N], ans[N];
map<int, int> cnt;

int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);

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

	for (auto&& [a, b] : cnt)
		ile[b]++;
	
	for (int i = 1; i <= n; i++) {
		if (ile[i] == 0)
			continue;
		
		int j = 1;
		while (j <= i) {
			int k = (i / (i / j)) + 1;

			ans[j] += ile[i] * (i / j);
			
			if (k <= n) {
				ans[k] -= ile[i] * (i / j);
			}

			j = k;
		}
	}

	for (int i = 1; i <= n; i++) {
		ans[i] += ans[i - 1];
		cout << ans[i] * i << ' ';
	}

	cout << '\n';

	return 0;
}