#include <bits/stdc++.h>
using namespace std;
void solve() {}
int main() {
  string s, ss;
  cin >> s;
  int counter = 1, index = 0;
  vector<pair<char, int> > v;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == s[i + 1])
      counter++;
    else {
      v.push_back(make_pair(s[i], counter));
      counter = 1;
    }
  }
  if (v.size() % 2 == 0 || v[v.size() / 2].second + 1 < 3) {
    cout << "0" << endl;
    return 0;
  }
  while (true) {
    index++;
    if (index + (v.size() / 2) > v.size() - 1) break;
    if ((v[v.size() / 2 + index].first != v[v.size() / 2 - index].first) ||
        (v[v.size() / 2 + index].second + v[v.size() / 2 - index].second < 3)) {
      cout << "0";
      return 0;
    }
  }
  cout << v[v.size() / 2].second + 1 << endl;
  return 0;
}
