#include <bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
typedef long int LI;
typedef unsigned long int ULI;
typedef long long int LL;
typedef unsigned long long int ULL;
const LL MOD = 1e9 + 7;
inline int scanInt() {
  int n = 0;
  char ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 1) + (n << 3) + (int)(ch - '0');
    ch = getchar();
  }
  return n * sign;
}
inline LL scanLong() {
  LL n = 0;
  char ch = getchar();
  LL sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 1) + (n << 3) + (LL)(ch - '0');
    ch = getchar();
  }
  return n * sign;
}
LL solve(vector<pair<char, LL> > segs) {
  if (segs.size() % 2 == 0) return 0;
  if (segs.size() == 1) {
    if (segs[0].second + 1 >= 3)
      return segs[0].second + 1;
    else
      return 0;
  }
  LL mid = (segs.size() - 1) / 2;
  LL left = mid - 1, right = mid + 1;
  if (segs[mid].second + 1 < 3) return 0;
  while (left >= 0 && right < segs.size()) {
    if (segs[left].first == segs[right].first) {
      if (segs[left].second + segs[right].second >= 3) {
        left--;
        right++;
      } else
        return 0;
    } else
      return 0;
  }
  return segs[mid].second + 1;
}
int main() {
  string s;
  cin >> s;
  vector<pair<char, LL> > segs;
  pair<char, LL> curr = make_pair(s[0], 0);
  for (__typeof(s.length()) i = (0) - ((0) > (s.length()));
       i != (s.length()) - ((0) > (s.length()));
       i += 1 - 2 * ((0) > (s.length()))) {
    if (s[i] != curr.first) {
      segs.push_back(curr);
      curr = make_pair(s[i], 0);
    }
    curr.second++;
    if (i == s.length() - 1) segs.push_back(curr);
  }
  printf("%lld ", solve(segs));
  printf("\n");
}
