#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  s += '#';
  vector<pair<int, char> > norm;
  int cnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      cnt++;
    } else if (s[i] != s[i - 1]) {
      norm.push_back({cnt, s[i - 1]});
      cnt = 1;
    }
  }
  if (norm.size() % 2 and norm[norm.size() / 2].first + 1 > 2) {
    for (int i = 0; i < norm.size() / 2; i++) {
      if (norm[i].second != norm[norm.size() - 1 - i].second or
          norm[i].first + norm[norm.size() - 1 - i].first < 3) {
        cout << 0;
        return 0;
      }
    }
    cout << norm[norm.size() / 2].first + 1;
  } else {
    cout << 0;
  }
  return 0;
}
