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