#include <bits/stdc++.h>
using namespace std;
struct node {
  int next, ty, nm;
} A[1000010];
int tp, as, hd, s;
char ch[1000010];
void Delete(int i, int lt) {
  if (i == hd)
    hd = A[i].next;
  else if (!A[i].next)
    A[lt].next = 0;
  else
    A[lt].next = A[i].next;
}
int Check() {
  if (!A[hd].next) return 0;
  int mn = 1e9;
  for (int i = hd; i; i = A[i].next) {
    if (i == hd || !A[i].next)
      mn = min(mn, A[i].nm);
    else
      mn = min(mn, (A[i].nm + 1) / 2);
  }
  int lt = 0;
  for (int i = hd; i; i = A[i].next) {
    int k = mn * 2;
    if (i == hd || !A[i].next) k = mn;
    A[i].nm = max(0, A[i].nm - k);
  }
  for (int i = hd; i; i = A[i].next) {
    if (A[i].nm && A[i].ty == A[lt].ty) {
      A[lt].nm += A[i].nm, Delete(i, lt);
      continue;
    }
    if (!A[i].nm) {
      Delete(i, lt);
      continue;
    }
    lt = i;
  }
  return mn;
}
int main() {
  scanf(" %s", ch + 1);
  hd = 1;
  int ln = strlen(ch + 1);
  for (int i = 1; i <= ln; i++) {
    int f = ch[i] - 'a' + 1;
    if (f == A[tp].ty)
      A[tp].nm++;
    else
      A[tp].next = tp + 1, A[++tp].ty = f, A[tp].nm = 1;
  }
  A[0].next = 0;
  while (1) {
    int k = Check();
    if (!k) break;
    as += k;
  }
  printf("%d\n", as);
  return 0;
}
