#include <iostream>
#include <map>
#include <algorithm>

int cntBits(int value) {
    int num_bits=0;
    for(size_t i = 0; i < 32 ; ++i, value >>= 1) {
        if ((value & 1) == 1) ++num_bits;
    }
    return num_bits;
}

struct cntBitsCmp {
    bool operator()(int a, int b) {
        return cntBits(a) < cntBits(b);
    }
};

using namespace std;

int main() {
	std::map<int,int,cntBitsCmp> myMap =  {
        {128,2},
        {3,4}
    };
    for(std::map<int,int,cntBitsCmp>::const_iterator i=myMap.begin() ; i != myMap.end() ; ++i) {
        cout << i->first << " " << i->second << endl;
    }
	return 0;
}