#include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<pair<char, int> > v;
inline bool check(const vector<pair<char, int> > &v) {
  if ((int)v.size() % 2 == 0) return false;
  int len = (int)v.size();
  for (int i = 0; i < len / 2; ++i) {
    if (v[i].first != v[len - i - 1].first) return false;
    if (v[i].second + v[len - i - 1].second < 3) return false;
  }
  if (v[len / 2].second < 2) return false;
  return true;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cout << fixed << setprecision(12);
  cin >> s;
  n = s.length();
  char last = s[0];
  int cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i] != last) {
      v.push_back({last, cnt});
      last = s[i];
      cnt = 1;
    } else
      ++cnt;
  }
  v.push_back({last, cnt});
  if (!check(v))
    cout << "0\n";
  else
    cout << v[(int)v.size() >> 1].second + 1 << endl;
  return 0;
}
