#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.length() < 2) {
    cout << 0;
    return 0;
  }
  vector<pair<char, int> > a(1, {s[0], 1});
  for (int i = 1; i < s.length(); i++) {
    if (s[i] == s[i - 1])
      a.back().second++;
    else
      a.push_back({s[i], 1});
  }
  string h;
  h += s[0];
  for (int i = 1; i < s.length(); i++) {
    if (s[i] != s[i - 1]) h += s[i];
  }
  string k = h;
  reverse(k.begin(), k.end());
  if (k != h) {
    cout << 0;
    return 0;
  }
  for (int i = 0, j = int(a.size()) - 1; i < int(a.size()) / 2; i++, j--) {
    if (a[i].second + a[j].second < 3) {
      cout << 0;
      return 0;
    }
  }
  cout << (a[int(a.size()) / 2].second < 2 ? 0
                                           : a[int(a.size()) / 2].second + 1);
}
