#include <bits/stdc++.h>
using namespace std;
struct seq {
  int num;
  char color;
};
int main() {
  string s;
  cin >> s;
  int i = 1, N = 0, j;
  seq temp;
  vector<seq> arr;
  temp.num = 1;
  temp.color = s[0];
  while (s[i] != '\0') {
    if (s[i] == temp.color) {
      temp.num++;
    } else {
      arr.push_back(temp);
      temp.num = 1;
      temp.color = s[i];
      N++;
    }
    i++;
  }
  arr.push_back(temp);
  N++;
  if (N % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  i = 0;
  j = N - 1;
  while (i < j) {
    if (arr[i].color == arr[j].color) {
      if (arr[i].num + arr[j].num >= 3) {
        i++;
        j--;
      } else {
        break;
      }
    } else {
      break;
    }
  }
  if (i == j) {
    if (arr[i].num + 1 >= 3) {
      cout << arr[i].num + 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    cout << 0 << endl;
  }
}
