#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<pair<char, int> > v;
  s = " " + s;
  s += '$';
  int cnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1])
      cnt++;
    else if (s[i - 1] != ' ') {
      v.push_back({s[i - 1], cnt});
      cnt = 1;
    }
  }
  if ((int)v.size() % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  int mid = (int)v.size() / 2;
  int i = 0;
  while (mid + i < (int)v.size()) {
    if (v[mid + i].second + v[mid - i].second <= 2) {
      cout << 0 << endl;
      return 0;
    }
    if (v[mid + i].first != v[mid - i].first) {
      cout << 0 << endl;
      return 0;
    }
    i++;
  }
  cout << v[mid].second + 1 << endl;
}
