#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;	
}