#include #include #include #define ull unsigned long long using namespace std; int countOnes(ull a) { int c = 0; for (int i = 0; i < 40; ++i) { if ((a & 1) == 1) { ++c; } a >>= 1; } return c; } int main() { string s; cin >> s; if (s[0] == 0) { cout << "-1\n"; return 0; } ull bitmask = ((ull)1 << s.length()) - 1; ull currentState = 0, bestState = 0; int ones = 0; for (int i = 0; i < s.length(); ++i) { currentState <<= 1; currentState |= (s[i] == '0' ? 0 : 1); ones += s[i] == '0' ? 0 : 1; } bestState = currentState; int iter = 0; for (int j = 0; j < 39 && currentState != bitmask; ++j) { for (int i = 1; i < 40; ++i) { ull st = (currentState | (currentState >> i)); int z = countOnes(st); if (z > ones) { bestState = st; ones = z; } } currentState = bestState; ++iter; } cout << iter << endl; return 0; }