#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int l = 0, r = s.size() - 1, z = 3;
  while (l < r && s[l] == s[r] && z >= 3) {
    char c = s[l];
    z = 0;
    while (s[l] == c) {
      l++;
      z++;
    }
    while (s[r] == c && r >= l) {
      r--;
      z++;
    }
  }
  if (l > r && z >= 2) {
    cout << z + 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
