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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    unordered_map<int, int> counts;
    vector<int> countsList;
    vector<int> stamps;

    stamps.resize(n);

    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        counts[num]++;
    }

    for (auto &count : counts) {
        countsList.push_back(count.second);
    }
    counts.clear();
    for (auto &count : countsList) {
        counts[count]++;
    }

    unordered_map<int, int>::iterator iter;
    for (int j = 0; j < n; j++) {
        if (counts.size() > 0) {
            iter = counts.begin();
            while (iter != counts.end()) {
                if (iter->first > j) {
                    stamps[j] += (iter->first - (iter->first % (j + 1))) * iter->second;
                    iter++;
                } else {
                    iter = counts.erase(iter);
                }
            }
        } else {
            break;
        }
    }

    for (int j = 0; j < n; j++) {
        cout << stamps[j] << " ";
    }
    cout << endl;
}