#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  int i = 0, n = s.size(), j = n - 1;
  char ch;
  int d = 0;
  while (i <= j) {
    ch = s[i];
    if (s[j] != ch) {
      cout << 0;
      return 0;
    }
    d = 0;
    while (s[i] == ch && i < n) d++, i++;
    if (j > i)
      while (s[j] == ch && j >= 0) d++, j--;
    if (i > j && d > 1) break;
    if (i == j || d < 3) {
      cout << 0;
      return 0;
    }
  }
  cout << d + 1;
  return 0;
}
