#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  set<int> s;
  for (int i = 0; i < N; i++) s.insert(i);
  bool flag = true;
  while (flag && s.size() > 1) {
    flag = false;
    vector<int> v;
    for (auto x : s) v.push_back(x);
    for (int i = 0; i < v.size() - 1; i++) {
      if (S[v[i]] != S[v[i + 1]]) {
        flag = true;
        s.erase(v[i]);
        s.erase(v[i + 1]);
        i++;
      }
    }
  }
  cout << N - s.size() << endl;
}
