#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int pos = 0;
  vector<int16_t> block = {};
  for (int i = 0; i < N; i++) {
    block.push_back(S[i]);
  }
  while (1) {
    if (block.size() == 1) break;
    if (block[pos] == block[pos + 1]) {
      pos++;
    } else {
      auto it = block.begin();
      block.erase(it + pos, it + pos + 2);
      pos = 0;
    }
    if (block.size() == pos + 1 || block.size() == 0) break;
  }
  cout << N - block.size() << endl;
  return 0;
}
