#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<int,int> m;
    multimap<int,int,greater<int>> mm;

    for(int i = 0; i < 40; ++i)
    {
        int v = rand()%20;
        m[v]++;
        cout << v << " ";
    }
    cout << endl;

    for(auto v : m)
        mm.insert(make_pair(v.second,v.first));

    for(auto v : mm)
        for(int i = 0; i < v.first; ++i)
            cout << v.second << " ";
    cout << endl;

}
