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
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int x;
    map<int,int>m;
    for(int i = 0;i<n;++i){
        cin>>x;
        if(m.count(x)==0){
            m.insert({x,1});
        }
        else{
            int new_val=m[x];
            m.erase(x);
            m.insert({x,new_val+1});
        }
    }
    vector<int>tab;
    for (auto i = m.begin(); i != m.end(); i++){
        tab.push_back(i->second);
    }
    sort(tab.begin(),tab.end());
    reverse(tab.begin(),tab.end());
    //4 3 2
    //9 5 2
    //4 4 4 3 3 2 1 1
    int maks = tab[0];
    vector<int>res;
    while(maks>0){
        int i = 0;
        int sum = 0;
        while(i<tab.size() && tab[i]>=maks){
            sum+=int(tab[i]/maks)*maks;
            i++;
        }
        res.push_back(sum);
        --maks;
    }
    for(int i = res.size()-1;i>=0;--i){
        cout<<res[i]<<" ";
    }
    for(int i = 0;i<n-res.size();++i){
        cout<<0<<" ";
    }
    return 0;

}