#include #include #include #include using namespace std; void getNegabinary(string str){ int i = strlen(str.c_str()); if(i>=2){ if(str[i-1] == '0'){ str[i-1] = '1'; cout << str << endl; return; }else if(str[i-2] == '1'){ if((strlen(str.c_str()) == 2)&&(str[0] == '1')&&(str[1] == '1')){ cout << "0" << endl; return; } str[i-1] = '0'; str[i-2] = '0'; cout << str << endl; return; }else{ if(str[i-3] == '0'){ str[i-3] = '1'; str[i-2] = '1'; str[i-1] = '0'; cout << str << endl; return; }else{ int j = i-3; for(int k = i-3; k >= 0; k--){ if(i % 2 == 0){ if(((str[j] == '0')&&(j%2 == 1)) || ((str[j] == '1')&&(j%2 == 0))){ if(j%2==0)str[j] = '1'; else str[j] = '0'; for(int l = j; l < i; l++){ if(str[l] == '0')str[l] = '1'; else str[l] = '0'; } if((str[1] == '0')&&(str[0] == '0')){ for(int f = 2; f < i; f++){ cout << str[f]; } cout << endl; return; }else cout << str << endl; return; } }else{ if(((str[j] == '0')&&(j%2 == 0)) || ((str[j] == '1')&&(j%2 == 1))){ if(j%2==0)str[j] = '1'; else str[j] = '0'; for(int l = j; l < i; l++){ if(str[l] == '0')str[l] = '1'; else str[l] = '0'; } if((str[1] == '0')&&(str[0] == '0')){ for(int f = 2; f < i; f++){ cout << str[f]; } cout << endl; return; }else cout << str << endl; return; } } j--; } if((str[1] == '0')&&(str[0] == '0')){ for(int f = 2; f < i; f++){ cout << str[f]; } cout << endl; return; } for(int l = i-1; l >= 0; l--){ if(str[l] == '0')str[l] = '1'; else str[l] = '0'; } str = "11" + str; cout << str << endl; return; } } } } int main() { string str; string str2; while(cin.good()){ cin >> str; if((strlen(str.c_str())>1000000)||(strlen(str.c_str())<1)) return 0; if(str == str2)return 0; if(strlen(str.c_str()) == 1){ if(str[0] == '1')cout << "110" << endl; else cout << "1" << endl; }else getNegabinary(str); str2 = str; } return 0; }