#include using namespace std; using ll = long long; #ifdef LOCAL #include #else #define debug(...) #endif vector> run_length_encodeing(const string& S) { vector> res; for (auto c : S) { if (!res.empty() && c == res.back().first) { res.back().second++; } else { res.emplace_back(c, 1); } } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); string S; cin >> S; auto res = run_length_encodeing(S); int ans = 0; stack> stk; for (auto&& [c, cnt] : res) { if (!stk.empty() && stk.top().first == '1' && c == '0') { auto [c2, cnt2] = stk.top(); ans += cnt2 / 2; cnt--; } if (stk.empty()) { stk.emplace(c, cnt); } else if (stk.top().first == c) { stk.top().second += cnt; } else if (cnt > 0) { stk.emplace(c, cnt); } } cout << ans << endl; }