#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  char ch;
  cin >> s;
  int l = s.size();
  int i = 0, ii = i, j = l - 1, jj = j;
  set<char> st;
  for (auto k : s) st.insert(k);
  if (st.size() == 1) {
    if (l == 1)
      cout << "0\n";
    else
      cout << l + 1 << endl;
    return 0;
  }
  bool flag = true;
  while (i < j) {
    if (s[i] == s[j]) {
      ch = s[i];
      while (s[i] == ch && i < l - 1) i++;
      while (s[j] == ch && j > 0) j--;
    }
    if (s[i] != s[j] || (i - ii + jj - j) < 3) {
      flag = false;
      break;
    }
    ii = i;
    jj = j;
  }
  if (!flag)
    cout << "0\n";
  else
    cout << i - j << endl;
}
