#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
multimap<int, int> arrays = {{8, 1}, {5, 1}, {6, 1}, {1, 1}, {4, 0}, {11, 0}, {7, 0}};
multimap<int, int> newArrays;
string secondArray("\nsecond array:\t");
cout << "first array:\t";
for(const auto& i : arrays) {
cout << i.first << '\t';
secondArray += to_string(i.second) + '\t';
}
cout << secondArray << endl << endl;
auto it = begin(arrays);
while(it != end(arrays)) {
if(it->second != 0) {
++it;
} else {
newArrays.insert(*it);
it = arrays.erase(it);
}
}
secondArray = "\nsecond array:\t";
cout << "first array:\t";
for(const auto& i : arrays) {
cout << i.first << '\t';
secondArray += to_string(i.second) + '\t';
}
cout << secondArray << "\n\nfirst new array:\t";
secondArray = "\nsecond new array:\t";
for(const auto& i : newArrays) {
cout << i.first << '\t';
secondArray += to_string(i.second) + '\t';
}
cout << secondArray << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJbXVsdGltYXA8aW50LCBpbnQ+IGFycmF5cyA9IHt7OCwgMX0sIHs1LCAxfSwgezYsIDF9LCB7MSwgMX0sIHs0LCAwfSwgezExLCAwfSwgezcsIDB9fTsKCW11bHRpbWFwPGludCwgaW50PiBuZXdBcnJheXM7CglzdHJpbmcgc2Vjb25kQXJyYXkoIlxuc2Vjb25kIGFycmF5Olx0Iik7CgkKCWNvdXQgPDwgImZpcnN0IGFycmF5Olx0IjsKCQoJZm9yKGNvbnN0IGF1dG8mIGkgOiBhcnJheXMpIHsKCQljb3V0IDw8IGkuZmlyc3QgPDwgJ1x0JzsKCQlzZWNvbmRBcnJheSArPSB0b19zdHJpbmcoaS5zZWNvbmQpICsgJ1x0JzsKCX0KCWNvdXQgPDwgc2Vjb25kQXJyYXkgPDwgZW5kbCA8PCBlbmRsOwoKCWF1dG8gaXQgPSBiZWdpbihhcnJheXMpO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