#include <bits/stdc++.h>
using namespace std;
void hike() {
  string s;
  cin >> s;
  vector<pair<char, int64_t>> a;
  a.emplace_back(s[0], 1);
  int64_t n = s.length();
  for (int64_t i = 1; i < n; ++i) {
    if (s[i] == a.back().first)
      a.back().second++;
    else
      a.emplace_back(s[i], 1);
  }
  int64_t k = a.size(), m = k >> 1;
  if (k % 2 == 0 || a[m].second == 1) {
    cout << 0 << "\n";
    return;
  }
  for (int64_t i = 0, j = k - 1; i < j; ++i, --j) {
    if (a[i].first != a[j].first || a[i].second + a[j].second == 2) {
      cout << 0 << "\n";
      return;
    }
  }
  cout << a[m].second + 1 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int64_t t = 1;
  while (t--) hike();
  return 0;
}
