#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  string s;
  cin >> s;
  int N = s.size();
  string tmp = "";
  while (true) {
    if (s.size() == 0) break;
    vector<int> removed(s.size());
    bool change = false;
    int n_removed = 0;
    int head = 0;
    int last = s.size() - 1;
    while (head < last) {
      if (s[head] != s[head + 1]) {
        removed[head] = 1;
        removed[head + 1] = 1;
        head += 2;
        change = true;
        n_removed += 2;
      } else {
        ++head;
      }
      if (head >= last) break;
      if (s[last] != s[last - 1]) {
        removed[last] = 1;
        removed[last - 1] = 1;
        last -= 2;
        change = true;
        n_removed += 2;
      } else {
        --last;
      }
    }
    if (!change) break;
    tmp.resize(s.size() - n_removed);
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (removed[i] == 0) tmp[j++] = s[i];
    }
    s = tmp;
  }
  cout << N - s.size() << endl;
  return 0;
}
