#include #include using namespace std; int main() { string S; cin >> S; int N = S.length(); int flips = 0; int balance = 0; // 1s - 0s for (int i = 0; i < N; ++i) { if (S[i] == '1') { balance++; } else { balance--; } // If at any point balance goes negative, fix it by flipping a 0 if (balance < 0) { flips++; balance += 2; // flip the current 0 to 1 } } cout << flips << endl; return 0; }