#include <bits/stdc++.h>
using namespace std;
string s;
int ys[1010101], L, x;
char yc[1010101];
int charsLeft, charAms[255];
inline int ceilDiv(int a) { return a - a / 2; }
inline void removeChars(char c, int am) {
  charAms[c] -= am;
  charsLeft -= charAms[c] == 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  cin >> s;
  char c = s[0];
  int m = 1;
  set<char> chars;
  for (unsigned i = 1; i < s.length(); i++) {
    if (s[i] != c) {
      ys[L] = m;
      yc[L] = c;
      charAms[c] += m;
      m = 0;
      chars.insert(c);
      c = s[i];
      L++;
    }
    m++;
  }
  chars.insert(c);
  charAms[c] += m;
  charsLeft = (int)chars.size();
  ys[L] = m;
  yc[L++] = c;
  int l = 0, r = L - 1;
  if (l == r - 1) {
    cout << min(ys[l], ys[r]);
    exit(0);
  }
  priority_queue<pair<int, int>> pq;
  for (int i = l + 1; i < r; i++) pq.push({ys[i], i});
  int mi;
  while (charsLeft > 1) {
    if (ys[l] < ys[r]) {
      mi = l;
    } else {
      mi = r;
    }
    while (!pq.empty() && pq.top().second <= l) pq.pop();
    while (!pq.empty() && pq.top().second >= r) pq.pop();
    if (!pq.empty() && ceilDiv(pq.top().first) - x <= ys[mi]) {
      mi = pq.top().second;
      pq.pop();
      int am = ceilDiv(ys[mi]) - x;
      removeChars(yc[mi], ys[mi]);
      removeChars(yc[l], am);
      removeChars(yc[r], am);
      x += am;
    }
    if (mi == l) {
      x += ys[l];
      removeChars(yc[l], ys[l]);
      removeChars(yc[r], ys[l]);
      ys[r] -= ys[l];
      l++;
    } else if (mi == r) {
      x += ys[r];
      removeChars(yc[l], ys[r]);
      removeChars(yc[r], ys[r]);
      ys[l] -= ys[r];
      r--;
    }
  }
  cout << x;
}
