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

int main() {
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    std::vector<int> nums(n);
    for(int i = 0; i < n; ++i) {
        std::cin >> nums[i];
    }
    std::sort(nums.begin(), nums.end());
    std::vector<int> counts;
    int prev = nums[0], current_count = 0;
    for(auto num : nums) {
        if(num == prev) {
            ++current_count;
        } else {
            counts.push_back(current_count);
            prev = num;
            current_count = 1;
        }
    }
    counts.push_back(current_count);
    std::sort(counts.begin(), counts.end());

    int l = 0, limit = counts.size();
    int prev_sum = 0;
    for(int i = 1; i <= n; ++i) {
        while(l < limit && counts[l] < i) {
            ++l;
        }
        if(l >= limit) {
            std::cout << 0 << " ";
        } else {
            int result = 0;
            for(int j = l; j < limit; ++j) {
                result += counts[j] - counts[j] % i;
            }
            std::cout << result << " ";
        }
    }
    std::cout << "\n";
}