#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s;
  cin >> s;
  int n = s.size();
  if (n == 1) {
    cout << 0;
    return 0;
  }
  int ans = 0;
  int co = 1;
  vector<pair<char, int> > c;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      c.emplace_back(s[i - 1], co);
      co = 0;
    }
    co++;
  }
  c.emplace_back(s[n - 1], co);
  int k = c.size();
  if (k % 2 == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < k / 2; i++) {
    if ((c[i].first != c[k - 1 - i].first) ||
        (c[i].second + c[k - 1 - i].second < 3)) {
      cout << 0;
      return 0;
    }
  }
  if (c[k / 2].second == 1)
    cout << 0 << endl;
  else
    cout << c[k / 2].second + 1 << endl;
}
