#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
int n, m, T;
char s[maxn];
pair<int, int> a[maxn];
int main() {
  cin >> s + 1;
  s[0] = '+';
  int tot = 0;
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      a[++tot] = {s[i] - 'a', 1};
    } else {
      a[tot].second++;
    }
  }
  int mi = (tot + 1) / 2;
  if (tot % 2 == 0 || a[mi].second < 2) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= tot / 2; i++) {
    if (a[mi - i].first != a[mi + i].first ||
        a[mi - i].second + a[mi + i].second < 3) {
      printf("0\n");
      return 0;
    }
  }
  cout << a[mi].second + 1 << endl;
  return 0;
}
