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
#include <stdio.h>
#include <algorithm>

int main()
{
	int count;
	scanf("%i", &count);

	int arr[300'000 + 2];
	for (int i=0; i<count; ++i) {
		int val;
		scanf("%i", &val);
		arr[i] = val;
	}

	std::sort(arr, arr + count);

	int divby[300'000 + 1] = {0};

	arr[count] = -1;
	int last = arr[0];
	int occur = 0;
	for (int i=0; i<count + 1; ++i) {
		if (arr[i] == last) {
			occur += 1;
		} else {
			for (int j=0; j<count && occur >= (j+1); ++j) {
				divby[j] += ((int) occur/(j+1)) * (j+1);
			}
			last = arr[i];
			occur = 1;
		}
	}

	for (int i=0; i<count-1; ++i) {
		printf("%i ", divby[i]);
	}
	printf("%i\n", divby[count-1]);
	return 0;
}