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
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>

int main() {
    int n;
    std::cin >> n;
    std::cin.ignore(); // Ignore newline after reading n

    std::string line;
    std::getline(std::cin, line);
    std::istringstream iss(line);
    std::string city;
    std::map<std::string, int> cityCounts;

    // Count occurrences of each city
    while (iss >> city) {
        cityCounts[city]++;
    }

    int maxStamps = 0;
    // Map of counts to the number of cities having that count
    std::map<int, int> counts;
    for (const auto& pair : cityCounts) {
        counts[pair.second]++;
        if (pair.second > maxStamps) {
            maxStamps = pair.second;
        }
    }

    std::vector<std::pair<int, int>> countCounts;
    for (const auto& count : counts) {
        countCounts.push_back(count);
    }
    // Sort in ascending order of stamp counts (implicitly done by the map)
    
    std::string outStr = std::to_string(n); // for k = 1

    for (int k = 2; k <= maxStamps; ++k) {
        int stampsGiven = 0;
        for (const auto& [cityCnt, numCities] : countCounts) {
            if (cityCnt >= k) {
                stampsGiven += (cityCnt / k) * numCities * k;
            }
        }
        outStr += " " + std::to_string(stampsGiven);
    }

    // Handle cases where n > maxStamps
    for (int i = maxStamps + 1; i <= n; ++i) {
        outStr += " 0";
    }

    std::cout << outStr << std::endl;

    return 0;
}