#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int lc[maxn], rc[maxn], a[maxn], val[maxn];
char s[maxn];
int Min(int i, int j) { return a[i] < a[j] ? i : j; }
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  int now = 1;
  a[1] = 1, val[1] = s[1] - 'a';
  for (int i = 2; i <= n; i++) {
    if (s[i] == s[i - 1])
      a[now]++;
    else
      now++, a[now]++, val[now] = s[i] - 'a';
  }
  int ans = 0;
  a[0] = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) lc[i] = i - 1, rc[i] = i + 1;
  int head = 1, ed = now;
  while (now > 1) {
    int cur = rc[head];
    int mins = 0;
    while (rc[cur] <= ed) {
      mins = Min(mins, cur);
      cur = rc[cur];
    }
    int cost = (a[mins] + 1) / 2 * 2;
    while (now > 1 && cost >= 2 * a[head])
      cost = 2 * a[head], head = rc[head], now--;
    while (now > 1 && cost >= 2 * a[ed]) cost = 2 * a[ed], ed = lc[ed], now--;
    a[head] -= cost / 2, a[ed] -= cost / 2;
    cur = rc[head];
    while (rc[cur] <= ed) {
      if (a[cur] <= cost) {
        int l = cur;
        while (a[cur] <= cost && rc[cur] <= ed)
          a[cur] -= cost, cur = rc[cur], now--;
        int u = lc[cur], v = cur;
        rc[u] = v, lc[v] = u;
      } else
        a[cur] -= cost;
    }
    ans += cost / 2;
  }
  printf("%d\n", ans);
}
