#include <bits/stdc++.h>
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;
template <typename T>
void MACRO_VAR_Scan(T &t) {
  cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
  cin >> first;
  MACRO_VAR_Scan(rest...);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  string s;
  MACRO_VAR_Scan(s);
  ;
  int64 n = s.size();
  bool same = true;
  int64 st = 0, lst = -1, ans = 0;
  for (int64 i = 0; i < (n); ++i) {
    if (i > 0) same &= (s[i] == s[i - 1]);
    if (s[i] == '0')
      --st;
    else
      ++st;
    if (st == 0) {
      ans += i - lst;
      lst = i;
    }
  }
  if (same) {
    cout << (0);
    cout << endl;
    ;
    return 0;
  }
  if (st != 0) {
    ans += n - 1 - lst - st;
  }
  cout << (ans);
  cout << endl;
  ;
  return 0;
}
