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

constexpr int MAX_N = 300001;

int a[MAX_N], res[MAX_N];
std::pair<int, int> b[MAX_N];

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n;
	std::cin >> n;

	for(int i = 0; i < n; ++i)
		std::cin >> a[i];
	
	std::sort(a, a+n);

	a[n] = a[n-1]+1;
	int cnt = 1;
	for(int i = 1; i <= n; ++i)
	{
		b[i].second = i;
		if(a[i-1] != a[i])
			++b[cnt].first,
			cnt = 0;
		++cnt;
	}
	std::sort(b, b+(n+1), std::greater<>());

	for(int i = 1; i <= n; ++i)
		for(int j = 0; b[j].first; ++j)
			res[i] += b[j].first*(b[j].second/i)*i;

	for(int i = 1; i <= n; ++i)
		std::cout << res[i] << ' ';
	std::cout << '\n';

	return 0;
}