#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  vector<char> A;
  char prev = 'a';
  for (const auto &s : S) {
    if (prev != s) {
      A.push_back(s);
      prev = s;
    }
  }
  int n = S.length();
  int m = A.size();
  if (m % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < m / 2; i++) {
    if (A[i] != A[m - i - 1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  int l = 0, r = n - 1;
  for (int i = 0; i < m / 2; i++) {
    int cnt = 0;
    while (S[l] == A[i]) {
      l++;
      cnt++;
    }
    while (S[r] == A[i]) {
      r--;
      cnt++;
    }
    if (cnt < 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  int ans = 0;
  while (S[l] == A[m / 2]) {
    l++;
    ans++;
  }
  cout << (ans >= 2 ? ans + 1 : 0) << endl;
}
