#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;
    for (int i = 0; i < s.size() - 1; ++i) {
      if (removed[i]) continue;
      if (s[i] != s[i + 1]) {
        removed[i] = 1;
        removed[i + 1] = 1;
        i = max(-1, i - 2);
        change = true;
      }
    }
    if (!change) break;
    tmp = "";
    for (int i = 0; i < s.size(); ++i) {
      if (removed[i] == 0) tmp += s[i];
    }
    s = tmp;
  }
  cout << N - s.size() << endl;
  return 0;
}
