#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = s.size();
  vector<pair<char, int>> a;
  for (int i = 0; i < n; i++) {
    if (i > 0 && a.back().first == s[i]) {
      a.back().second++;
    } else {
      a.push_back({s[i], 1});
    }
  }
  int m = a.size();
  if (m % 2 == 0) {
    cout << 0 << "\n";
    return 0;
  }
  bool flag = true;
  flag = flag && (a[m / 2].second >= 2);
  for (int i = 0; i < m / 2; i++) {
    flag = flag && (a[i].first == a[m - 1 - i].first);
    flag = flag && (a[i].second + a[m - 1 - i].second >= 3);
  }
  if (flag) {
    cout << a[m / 2].second + 1 << "\n";
  } else {
    cout << 0 << "\n";
  }
  return 0;
}
