#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i;
  string str;
  cin >> str;
  n = str.length();
  int start = 0, end = n - 1;
  bool valid = true;
  while (valid && start < end) {
    int cntF = 1, sF = start;
    while (str[sF] == str[sF + 1]) sF++, cntF++;
    int cntB = 0, sB = end;
    while (sF < sB && str[start] == str[sB]) sB--, cntB++;
    if (cntF + cntB >= 3 && cntF > 0 && cntB > 0) {
    } else if (sF == sB) {
      cout << cntF + cntB + 1 << '\n';
      return 0;
    } else {
      valid = false;
      break;
    }
    start = sF + 1, end = sB;
  }
  cout << 0 << '\n';
  return 0;
}
