#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c = 0, d, i, j = 3, k, l;
  string mr;
  cin >> mr;
  d = mr.size();
  d--;
  k = 0;
  char n;
  while (d > c && mr[d] == mr[c] && j >= 3) {
    j = 0;
    n = mr[c];
    while (mr[c] == n) {
      j++;
      c++;
    }
    while (mr[d] == n && d > c) {
      j++;
      d--;
    }
  }
  if (j >= 2 && c > d)
    cout << j + 1;
  else
    cout << "0";
  cout << endl;
  return 0;
}
