#include <iostream>
#include <map>
#include <iterator>
using namespace std;
int main() {
map<int,int> mymap = {{1,0},{2,1},{9,2},{10,3},{11,4}};
for(auto it = mymap.rbegin(); it != mymap.rend(); ){
auto v = --(it.base());
cout << "erasing: " << v->first << endl;
v = mymap.erase(v);
it = map<int,int>::reverse_iterator(v);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8aXRlcmF0b3I+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCW1hcDxpbnQsaW50PiBteW1hcCA9IHt7MSwwfSx7MiwxfSx7OSwyfSx7MTAsM30sezExLDR9fTsKCWZvcihhdXRvIGl0ID0gbXltYXAucmJlZ2luKCk7IGl0ICE9IG15bWFwLnJlbmQoKTsgKXsKCSAgICBhdXRvIHYgPSAtLShpdC5iYXNlKCkpOwogICAgCWNvdXQgPDwgImVyYXNpbmc6ICIgPDwgdi0+Zmlyc3QgPDwgZW5kbDsKCSAgICB2ID0gbXltYXAuZXJhc2Uodik7CiAgICAJaXQgPSBtYXA8aW50LGludD46OnJldmVyc2VfaXRlcmF0b3Iodik7Cgl9CglyZXR1cm4gMDsKfQ==