#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int l = 0, r = s.size() - 1;
  char cur = '?';
  int cnt = 0;
  vector<pair<int, char>> v;
  while (l <= r) {
    if (s[l] != s[r]) {
      cout << 0 << endl;
      return 0;
    }
    cur = s[l];
    cnt = 0;
    while (s[l] == cur && l <= r) {
      cnt++;
      l++;
    }
    while (s[r] == cur && l <= r) {
      cnt++;
      r--;
    }
    v.push_back(make_pair(cnt, cur));
  }
  bool y = 1;
  for (int i = 0; i < v.size() - 1; i++) {
    if (v[i].first < 3) y = 0;
  }
  if (y && v[v.size() - 1].first >= 2)
    cout << v[v.size() - 1].first + 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
