#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T>
bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
const int MAXN = 3e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1;
int N, M;
char S[MAXN];
pair<char, int> P[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> S;
  N = strlen(S);
  P[M++] = {S[0], 1};
  for (int i = (int)(1); i <= (int)(N - 1); ++i) {
    if (S[i] == P[M - 1].first) {
      P[M - 1].second++;
    } else {
      P[M++] = {S[i], 1};
    }
  }
  if (M % 2 == 0) do {
      cout << 0 << '\n';
      return 0;
    } while (0);
  int l = M / 2, r = M / 2;
  if (P[l].second < 2) do {
      cout << 0 << '\n';
      return 0;
    } while (0);
  int ans = P[l].second + 1;
  while (l) {
    l--;
    r++;
    if (P[l].first != P[r].first || P[l].second + P[r].second < 3) do {
        cout << 0 << '\n';
        return 0;
      } while (0);
  }
  cout << ans << endl;
  return 0;
}
