#include <bits/stdc++.h>
using namespace std;
int abs(int a) { return (a > 0) ? a : -a; }
int main() {
  string s;
  cin >> s;
  vector<int> vec;
  int tmp = 0;
  bool check = true;
  for (int i = 0; i < s.size(); i++) {
    if (i == 0)
      tmp++;
    else {
      if (s[i] == s[i - 1]) {
        tmp++;
        if (i == s.size() - 1) {
          vec.push_back(tmp);
        }
      } else {
        if (check) tmp *= -1;
        vec.push_back(tmp);
        tmp = 1;
        check = !check;
      }
    }
  }
  if (s.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  int era = 0, res = vec[0];
  check = true;
  while (check) {
    for (int i = 0; i < vec.size(); i++) {
      if (vec[i] == 0) {
        vec.erase(vec.begin() + i);
        i--;
      }
    }
    for (int i = 1; i < vec.size(); i++) {
      if (vec[i] * vec[i - 1] > 0) {
        vec[i - 1] += vec[i];
        vec.erase(vec.begin() + i);
        i--;
      }
    }
    check = false;
    for (int i = 1; i < vec.size(); i++) {
      if (vec[i] * vec[i - 1] < 0) {
        check = true;
        era += 2 * min(abs(vec[i - 1]), abs(vec[i]));
        if (abs(vec[i]) < abs(vec[i - 1])) {
          if (vec[i] > 0)
            vec[i - 1] += abs(vec[i]);
          else
            vec[i - 1] -= abs(vec[i]);
          vec[i] = 0;
        } else {
          if (vec[i] > 0)
            vec[i] -= abs(vec[i - 1]);
          else
            vec[i] += abs(vec[i - 1]);
          vec[i - 1] = 0;
        }
      }
    }
  }
  cout << era << endl;
  return 0;
}
