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

int main() {
  std::map<char, int> m{{'a', 5},
                        {'b', 5},
                        {'f', 3},
                        {'k', 8},
                        {'m', 5},
                        {'w', 8},
                        {'a', 8},
                        {'c', 8},
                        {'z', 1}};

  std::vector<std::pair<char, int>> v{m.begin(), m.end()};

  std::stable_sort(v.begin(), v.end(), [](const auto& l, const auto& r) {
    return l.second > r.second;
  });

  for (const auto& item : v) {
    std::cout << item.first << " " << item.second << std::endl;
  }
}
