#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  bool erased = true;
  string s;
  cin >> s;
  int first_size = s.size();
  while (true) {
    for (j = 1; j < s.size() - 1; j++) {
      if (s.at(0) != s.at(j)) break;
    }
    if (j == s.size() - 1) break;
    if (erased == false || s.size() == 1) break;
    erased = false;
    for (i = 0; i <= s.size() - 2; i++) {
      if (s.at(i) != s.at(i + 1)) {
        erased = true;
        s.erase(s.begin() + i, s.begin() + i + 2);
        i++;
      }
    }
  }
  cout << first_size - (j + 1) << endl;
  return 0;
}
