#include <bits/stdc++.h>
using namespace std;
struct myhash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long modpow(long long base, long long exp, long long modulus) {
  base %= modulus;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
long long modinv(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  long long n = s.length();
  vector<pair<char, int>> f;
  f.push_back({s[0], 1});
  for (long long(i) = (1); i < (n); ++(i)) {
    if (s[i] != f[f.size() - 1].first) {
      f.push_back({s[i], 1});
    } else {
      f[f.size() - 1].second++;
    }
  }
  if (f.size() % 2 == 0) {
    cout << 0;
  } else {
    long long m = f[f.size() / 2].second;
    if (m < 2) {
      cout << 0;
      return 0;
    }
    for (long long(i) = (0); i < (f.size() / 2); ++(i)) {
      if (f[i].first != f[f.size() - (i + 1)].first) {
        cout << 0;
        return 0;
      }
      if (f[i].second + f[f.size() - (i + 1)].second < 3) {
        cout << 0;
        return 0;
      }
    }
    cout << m + 1;
  }
  return 0;
}
