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

int main() {
    int N;
    std::vector<int> cities;
    std::vector<int> sizes;

    scanf("%d", &N);
    for (int i=0; i<N; ++i) {
        int v;
        scanf("%d", &v);
        cities.push_back(v);
    }

    std::sort(cities.begin(), cities.end());

    int last = -1;
    int cnt = 0;

    for (int v : cities) {
        if (v != last) {
            if (cnt > 0) {
                sizes.push_back(cnt);
            }
            last = v;
            cnt = 1;
        } else {
            cnt += 1;
        }
    }
    sizes.push_back(cnt);
    std::sort(sizes.begin(), sizes.end());

    int left = 0;

    for (int k=1; k<=N; k++) {
        int result = 0;
        for (int i=left; i<sizes.size(); ++i) {
            result += k * (sizes[i]/k);
            if (sizes[i] < k) {
                left = i+1;
            }
        }
        printf("%d ", result);
    }

    return 0;
}