#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
  string s;
  cin >> s;
  vector<int> v;
  vector<char> c;
  for (int i = 0, j = 0; i < s.size(); i = j) {
    int cnt = 0;
    c.push_back(s[i]);
    while (j < s.size() && s[i] == s[j]) {
      j++;
      cnt++;
    }
    v.push_back(cnt);
  }
  int a = v.size();
  if (a % 2 == 0 || v[a / 2] < 2) {
    cout << 0;
    return;
  }
  bool ok = 1;
  for (int i = 0; i < a / 2; i++) {
    ok &= (v[i] + v[a - 1 - i] > 2);
    ok &= (c[i] == c[a - 1 - i]);
  }
  cout << (ok ? v[a / 2] + 1 : 0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
