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