/*
お題:1のビットが3個ある二進表記文字列が与えられたとき、次に大きい
1のビットが3個ある二進表記文字列を求める。
例
111 -> 1011
1110 -> 10011
101100 -> 110001
*/
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string f623(string s)
{
const int len = s.length();
const int c0 = count(s.begin(), s.end(), '0');
const int c1 = count(s.begin(), s.end(), '1');
if (s.empty() || s[0] != '1' || c0 + c1 != len) {
return "INVALID";
}
for (int i = len - 1; i > 0; --i) {
if (s[i - 1] == '0' && s[i] == '1') {
return s.substr(0, i - 1) + f623(s.substr(i));
}
}
return '1' + string(c0 + 1, '0') + string(c1 - 1, '1');
}
int main()
{
for (string s; cin >> s; ) {
cout << s << " -> " << f623(s) << endl;
}
}
LyoK44GK6aGM77yaMeOBruODk+ODg+ODiOOBjDPlgIvjgYLjgovkuozpgLLooajoqJjmloflrZfliJfjgYzkuI7jgYjjgonjgozjgZ/jgajjgY3jgIHmrKHjgavlpKfjgY3jgYQKMeOBruODk+ODg+ODiOOBjDPlgIvjgYLjgovkuozpgLLooajoqJjmloflrZfliJfjgpLmsYLjgoHjgovjgIIK5L6LCjExMSAtPiAxMDExCjExMTAgLT4gMTAwMTEKMTAxMTAwIC0+IDExMDAwMQoqLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cmluZyBmNjIzKHN0cmluZyBzKQp7Cgljb25zdCBpbnQgbGVuID0gcy5sZW5ndGgoKTsKCWNvbnN0IGludCBjMCA9IGNvdW50KHMuYmVnaW4oKSwgcy5lbmQoKSwgJzAnKTsKCWNvbnN0IGludCBjMSA9IGNvdW50KHMuYmVnaW4oKSwgcy5lbmQoKSwgJzEnKTsKCWlmIChzLmVtcHR5KCkgfHwgc1swXSAhPSAnMScgfHwgYzAgKyBjMSAhPSBsZW4pIHsKCQlyZXR1cm4gIklOVkFMSUQiOwoJfQ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