#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
T gcd(T a, T b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int cnt = 1;
  vector<pair<char, int>> seg;
  for (int i = (int)(1); i < (int)(s.size()); i++) {
    if (s[i] == s[i - 1])
      cnt++;
    else {
      seg.push_back(make_pair(s[i - 1], cnt));
      cnt = 1;
    }
  }
  seg.push_back(make_pair(s[(int)s.size() - 1], cnt));
  if (seg.size() % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  int n = seg.size();
  for (int i = 0; i < (int)(n / 2); i++) {
    if (seg[i].first != seg[n - i - 1].first ||
        (seg[i].second + seg[n - i - 1].second) < 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (seg[n / 2].second >= 2)
    cout << seg[n / 2].second + 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
