#include <bits/stdc++.h>
using namespace std;
random_device rd;
mt19937 rnd(rd());
signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  string s;
  cin >> s;
  int n = (int)s.size(), ans = 0;
  vector<int> q;
  vector<bool> used(n, 0);
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) {
      if (used[i]) {
        bool fl = 1;
        if (i + 2 < n && s[i + 1] != s[i + 2]) fl = 0;
        if (fl && q.size() > 0 && s[q.back()] != s[i + 1]) {
          ans = max(ans, i - q.back());
          q.pop_back();
        }
      } else
        q.push_back(i);
      continue;
    }
    used[i] = 1;
    used[i + 1] = 1;
    if (ans == 0) ans = 1;
  }
  cout << ans << '\n';
  return 0;
}
