#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
template <class T>
T maxT(T a, T b) {
  return (a > b ? a : b);
}
template <class T>
T minT(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
void setmin(T &a, T b) {
  a = (a > b ? a : b);
}
template <class T>
void setmax(T &a, T b) {
  a = (a < b ? a : b);
}
void fileio() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
}
void ofileio() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void clock_out() {
  cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
void solve() {
  string s;
  cin >> s;
  string temp = "";
  vector<int> cnt;
  int c = 1;
  temp += s[0];
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      c++;
    } else {
      temp += s[i];
      cnt.push_back(c);
      c = 1;
    }
  }
  cnt.push_back(c);
  string w = temp;
  reverse((w).begin(), (w).end());
  if (w != temp) {
    cout << 0;
    return;
  } else {
    int pos = (cnt.size()) / 2;
    for (long long i = 0; i < pos; i++) {
      if ((cnt[i] + cnt[cnt.size() - i - 1]) < 3) {
        cout << 0;
        return;
      }
    }
    if (cnt[pos] >= 2)
      cout << cnt[pos] + 1;
    else
      cout << 0;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  1;
  long long t = 1;
  while (t--) {
    solve();
  }
  1;
  return 0;
}
