#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<pair<int, int> > a;
  a.push_back({1, (int)(s[0] - 'A')});
  for (int i = 1; i < (int)s.size(); i++) {
    char ch = s[i];
    int c = ch - 'A';
    if (c == a.back().second) {
      a.back().first++;
    } else {
      a.push_back({1, c});
    }
  }
  if ((int)a.size() % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (a[a.size() / 2].first + 1 < 3) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < (int)a.size() / 2; i++) {
    if (a[i].second != a[a.size() - 1 - i].second ||
        a[i].first + a[a.size() - 1 - i].first < 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << a[a.size() / 2].first + 1 << endl;
  return 0;
}
