#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string S;
  cin >> S;
  int orgS = S.size();
  if (S.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  int count = 0;
  while (S.size() > 0) {
    if (S.size() == 1) break;
    if (S.size() == 2) {
      if (S[0] != S[1]) {
        S = "";
      }
      break;
    }
    vector<int> mark(S.size(), 0);
    int marked = 0;
    for (int i = 0; i < S.size() - 1; i++) {
      if (mark[i] == 1) continue;
      if (S[i] != S[i + 1]) {
        mark[i] = mark[i + 1] = 1;
        marked++;
      }
    }
    string nS;
    for (int i = 0; i < S.size(); i++) {
      if (mark[i] == 0) {
        nS += S[i];
      }
    }
    if (marked == 0) break;
    S = nS;
  }
  cout << orgS - S.size() << endl;
}
