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

std::vector<int> v, a;
int answer[300001];

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

    int n, x;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> x;
        v.push_back(x);
    }
    std::sort(v.begin(), v.end());

    int last = v[0], counter = 1;
    for (int i = 1; i < n; i++) {
        if (v[i] != last) {
            a.push_back(counter);
            last = v[i];
            counter = 0;
        }
        counter++;
    }
    a.push_back(counter);
    std::sort(a.begin(), a.end());
    for (int i = 0; i < a.size(); i++) {
        counter = 1;
        while (counter <= a[i]) {
            answer[counter] += (a[i] / counter) * counter;
            counter++;
        }
    }

    for (int i = 1; i <= n; i++) {
        std::cout << answer[i] << ' ';
    }
}