#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
char s[N];
vector<pair<int, int> > v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> (s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j + 1 <= n && s[i] == s[j + 1]) ++j;
    v.push_back({s[i] - 'A', j - i + 1});
    i = j;
  }
  if (v.size() % 2 == 0)
    cout << 0 << endl;
  else {
    int m = v.size();
    if (v[m / 2].second < 2) {
      cout << 0 << endl;
      return 0;
    }
    for (int j = 1; m / 2 - j >= 0; j++)
      if (v[m / 2 - j].second + v[m / 2 + j].second < 3 ||
          v[m / 2 - j].first != v[m / 2 + j].first) {
        cout << 0 << endl;
        return 0;
      }
    cout << v[m / 2].second + 1 << endl;
  }
  return 0;
}
