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

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n;
    std::cin >> n;
    std::unordered_map<int, int> cities;
    for(int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        if(cities.contains(a)) {
            cities[a]++;
        }
        else {
            cities[a] = 1;
        }
    }

    int j = 1;
    while(j <= n) {
        int k = 0;
        auto i = cities.begin();
        while (i != cities.end()) {
            k += (i->second / j) * j;
            if(i->second == j) {
                i = cities.erase(i);
            }
            else {
                ++i;
            }
        }
        std::cout << k << " ";
        ++j;
    }
}