#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9 + 7;
using MIte = multimap<long, long, greater<long> >::iterator;
vector<int> CalcCandidate(string& S) {
  int idx = 0;
  vector<int> vpair;
  if (S.empty() || S.length() == 1) {
    return vpair;
  }
  while (1) {
    if (S[idx] != S[idx + 1]) {
      vpair.push_back(idx);
      idx += 2;
    } else {
      idx++;
    }
    if (idx >= S.length() - 1) {
      break;
    }
  }
  return vpair;
}
vector<int> CalcCandidate2(string& S, vector<int>& v) {
  int idx = 0;
  vector<int> vpair;
  for (int i = 0; i != v.size(); ++i) {
    if (S[idx] != S[idx + 1]) {
      vpair.push_back(idx);
    }
  }
  return vpair;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string S;
  cin >> S;
  vector<int> vpair = CalcCandidate(S);
  int cnt = 0;
  while (1) {
    vector<int> vnewpair;
    string newS;
    cnt += (2 * vpair.size());
    for (int i = 0; i != vpair.size(); ++i) {
      const int del1 = vpair[i];
      const int del2 = del1 + 1;
      if (i != 0) {
        if (vpair[i - 1] + 2 < vpair[i]) {
          for (int j = vpair[i - 1] + 2; j != vpair[i]; ++j) {
            newS.push_back(S[j]);
          }
        }
      } else {
        for (int j = 0; j != vpair[i]; ++j) {
          newS.push_back(S[j]);
        }
      }
      if (i == vpair.size() - 1) {
        if (vpair[i] + 2 < S.length()) {
          for (int j = vpair[i] + 2; j != S.length(); ++j) {
            newS.push_back(S[j]);
          }
        }
      }
    }
    S = newS;
    vpair = CalcCandidate(S);
    if (vpair.empty()) {
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}
