#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdint>
#include <limits>

//this result is who's bug??

int CountBit(std::int32_t N){
	int C = 0;

 	for (std::size_t i = 0; i < std::numeric_limits<std::int32_t>::digits; i++){
		if ((N&static_cast<std::int64_t>((1 << i)))>0) C++;
	}

	return C;
}

std::string ltostr(std::int64_t N){
	std::string str;
	bool F = false;
	std::string C = "01";
	for (size_t i = std::numeric_limits<std::int64_t>::digits+1;i>0; i--){
		if ((N&static_cast<std::int64_t>(1 << (i-1))) == 0 && F == false) continue;
		F = true;
		str += C[(N&static_cast<std::int64_t>(1 << (i-1))) > 0]  ;
	}

	return str;
}

std::string MakeHoge(std::string Bit){
	char* P = NULL;
	std::int64_t N =std::strtol(Bit.c_str(), &P, 2);//C99
	if (*P != '\0') return "Error";
	std::string R;
	for (std::int64_t i = N+1; i < std::numeric_limits<std::int64_t>::max(); i++)
	{
			//R = ltostr(N);//selfmade
		if (CountBit(i) == 3){
			R = ltostr(i);//selfmade
			break;
		}
	}
	return R;
}

bool Show(std::string P, std::string S){
	std::cout << P << " -> " << S << std::endl;

	return true;

}

int main(){
	std::int64_t MagicWord = 0;
	std::string P;
	std::string S;

	P = "111";
	S = MakeHoge(P);
	Show(P, S);

	P = "1110";
	S = MakeHoge(P);
	Show(P, S);

	P = "110100";
	S = MakeHoge(P);
	Show(P, S);
	return 0;
}
