#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
vector<pair<char, int> > a[maxn + 100];
stack<pair<char, int> > hel;
int main() {
  ios_base::sync_with_stdio(false);
  string second;
  cin >> second;
  int cnt = 1;
  char c = second[0];
  for (int i = 1; i < second.size(); i++) {
    if (second[i] == c)
      cnt++;
    else {
      a[1].push_back(pair<char, int>(c, cnt));
      cnt = 1;
      c = second[i];
    }
  }
  a[1].push_back(pair<char, int>(c, cnt));
  int ans = 0;
  for (int i = 1; i <= maxn; i++) {
    if (a[i].size() <= 1) {
      cout << ans;
      return 0;
    }
    int maxi = 1e8;
    for (int j = 0; j < a[i].size(); j++) {
      if (j == 0 or j == a[i].size() - 1) {
        maxi = min(maxi, a[i][j].second);
      } else {
        maxi = min(maxi, (a[i][j].second + 1) / 2);
      }
    }
    ans += maxi;
    for (int j = 0; j < a[i].size(); j++) {
      int p = 2;
      if (j == 0 or j == a[i].size() - 1) p = 1;
      if (a[i][j].second - p * maxi <= 0) continue;
      if (!hel.size()) {
        hel.push(pair<char, int>(a[i][j].first, a[i][j].second - p * maxi));
        continue;
      }
      pair<char, int> t = hel.top();
      if (t.first == a[i][j].first) {
        hel.pop();
        hel.push(
            pair<char, int>(t.first, t.second + a[i][j].second - p * maxi));
        continue;
      }
      hel.push(pair<char, int>(a[i][j].first, a[i][j].second - p * maxi));
    }
    while (hel.size()) {
      a[i + 1].push_back(hel.top());
      hel.pop();
    }
    reverse(a[i + 1].begin(), a[i + 1].end());
  }
  return 0;
}
