#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<pair<int, int> > v;
  char pre = '_';
  for (int i = 0; i < s.length(); i++) {
    int len = 0;
    while (i + len < s.length() && s[i + len] == s[i]) len++;
    i += len - 1;
    v.push_back(make_pair(s[i], len));
  }
  int ans = 0;
  if (v.size() & 1) {
    ans = v[v.size() / 2].second + 1;
    if (v[v.size() / 2].second < 2) ans = 0;
    for (int i = 0, j = v.size() - 1; i < j; i++, j--) {
      if (v[i].first != v[j].first || v[i].second + v[j].second < 3) {
        ans = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
