#include <bits/stdc++.h>
using namespace std;
char s[300008];
struct Node {
  char c;
  int v;
  Node() {}
  Node(char _c, int _v) {
    c = _c;
    v = _v;
  }
};
vector<Node> vec;
int gao() {
  if (vec.size() % 2 == 0) return 0;
  int ctr = vec.size() / 2;
  if (vec[ctr].v <= 1) return 0;
  for (int c = 1; ctr - c >= 0; ++c) {
    if (vec[ctr - c].v + vec[ctr + c].v <= 2 ||
        vec[ctr - c].c != vec[ctr + c].c)
      return 0;
  }
  return vec[ctr].v + 1;
}
int main() {
  scanf("%s", s);
  int Len = strlen(s);
  Node cur;
  cur.v = 1, cur.c = s[0];
  for (int i = 1; i < Len; ++i) {
    if (cur.c != s[i] && cur.v) {
      vec.push_back(cur);
      cur.c = s[i];
      cur.v = 1;
    } else if (cur.c == s[i]) {
      cur.v++;
    }
  }
  vec.push_back(cur);
  printf("%d\n", gao());
}
