#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int t;
struct node {
  char id;
  int num;
} ans[N];
string a;
int cot;
int main() {
  cin >> a;
  if (a.length() == 1) {
    cout << 0 << endl;
    return 0;
  }
  cot = 1;
  ans[cot].id = a[0];
  ans[cot].num = 1;
  for (register int i = 0; i <= a.length() - 2; ++i) {
    if (a[i + 1] == a[i])
      ans[cot].num++;
    else {
      ans[++cot].id = a[i + 1];
      ans[cot].num = 1;
    }
  }
  if (cot % 2 == 0 || ans[cot / 2 + 1].num < 2) {
    cout << 0 << endl;
    return 0;
  }
  int now = 1;
  int fg = 0;
  while (now != cot / 2 + 1) {
    if (ans[now].id != ans[cot - now + 1].id ||
        ans[now].num + ans[cot - now + 1].num < 3) {
      fg = 1;
      break;
    }
    now++;
  }
  if (!fg)
    cout << ans[cot / 2 + 1].num + 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
