#include <bits/stdc++.h>
using namespace std;
int read() {
  int num = 0, f = 1;
  char s = getchar();
  while (s > '9' or s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' and s <= '9') {
    num = num * 10 + (s - '0');
    s = getchar();
  }
  return num * f;
}
const int N = 1e5 * 3 + 10;
struct node {
  char s;
  int num;
} a[N], temp;
void pri(int f) {
  if (f)
    cout << a[f].num + 1 << endl;
  else
    cout << 0 << endl;
}
int main() {
  string s1;
  cin >> s1;
  int cnt = 0;
  for (int i = 0; i < s1.size(); i++) {
    temp.s = s1[i];
    temp.num = 0;
    for (int j = i; j < s1.size(); j++) {
      if (temp.s == s1[j])
        temp.num++, i = j;
      else {
        break;
      }
    }
    a[++cnt] = temp;
  }
  if (cnt % 2 == 0)
    pri(0);
  else if (cnt == 1 and a[1].num >= 2)
    pri(1);
  else if (a[cnt / 2 + 1].num <= 1)
    pri(0);
  else {
    int f = 1;
    int p = 1, q = cnt;
    while (p < q) {
      if (a[p].s == a[q].s and a[p].num + a[q].num >= 3) {
        p++, q--;
        continue;
      } else {
        f = 0;
        break;
      }
    }
    if (f != 0)
      pri(cnt / 2 + 1);
    else
      pri(0);
  }
  return 0;
}
