#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  s = s + " ";
  string p = "", q = "";
  vector<long long int> v;
  long long int a = 1;
  for (long long int i = 0; i <= s.size() - 2; i++) {
    if (s[i] != s[i + 1]) {
      p = p + s[i];
      v.push_back(a);
      a = 1;
    } else
      a++;
  }
  if (p.size() == 1 && v[0] > 1) {
    cout << v[0] + 1;
    return;
  }
  q = p;
  reverse((q).begin(), (q).end());
  if (p != q || v[p.size() / 2] < 2) {
    cout << 0;
    return;
  }
  for (long long int i = 1; i <= p.size() / 2; i++) {
    if (min(v[p.size() / 2 - i], v[p.size() / 2 + i]) >= 1 &&
        v[p.size() / 2 - i] + v[p.size() / 2 + i] >= 3)
      continue;
    else {
      cout << 0;
      return;
    }
  }
  cout << v[p.size() / 2] + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    solve();
    cout << "\n";
    ;
  }
}
