#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 0.000000001;
using namespace std;
char str[maxn];
int main() {
  cin >> str;
  int ff = 1, len = strlen(str), ans = 0;
  while (ff) {
    int c1 = 0, c2 = 0, tmp = 0;
    ff = 0;
    vector<int> q;
    vector<char> s;
    for (int i = 0; i < len; i++) {
      if (str[i] == str[i - 1]) {
        c2++;
        continue;
      }
      if (i) ff = 1;
      s.push_back(str[i]);
      tmp = max(tmp, c1 - max(0, c1 - c2));
      c1 = max(0, c1 - c2);
      q.push_back(c1);
      c1 = c2;
      c2 = 1;
    }
    tmp = max(tmp, c1 - max(0, (c1 - c2)));
    q.push_back(max(0, c1 - c2));
    tmp = max(tmp, c2 - max(0, (c2 - c1)));
    q.push_back(max(0, c2 - c1));
    ans += tmp;
    len = 0;
    for (int i = 1; i < q.size(); i++) {
      for (int j = 1; j <= q[i]; j++) str[len++] = s[i - 2];
    }
    str[len] = '\0';
  }
  cout << ans << endl;
}
