#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<pair<char, int>> bop;
  int prev = -1;
  for (int i = 0; i < s.size(); i++) {
    if (i == s.size() - 1 || s[i] != s[i + 1]) {
      bop.push_back(make_pair(s[i], i - prev));
      prev = i;
    }
  }
  if (bop.size() % 2 == 0) {
    puts("0");
    return 0;
  }
  int pos = bop.size() / 2;
  if (bop[pos].second < 2) {
    puts("0");
    return 0;
  }
  for (int i = 0; i < pos; i++) {
    if (bop[i].first != bop[bop.size() - 1 - i].first ||
        bop[i].second + bop[bop.size() - 1 - i].second < 3) {
      puts("0");
      return 0;
    }
  }
  printf("%d\n", bop[pos].second + 1);
}
