#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<pair<int, char> > a;
  int cnt = 1, ans = -1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1])
      cnt++;
    else {
      a.push_back({cnt, s[i - 1]});
      cnt = 1;
    }
  }
  a.push_back({cnt, s[s.size() - 1]});
  if (a.size() % 2) {
    for (int i = 0; i < a.size() / 2; i++) {
      if (a[i].second != a[a.size() - i - 1].second ||
          a[i].first + a[a.size() - i - 1].first < 3) {
        ans = 0;
        break;
      }
    }
    if (ans == -1)
      if (a[a.size() / 2].first < 2)
        ans = 0;
      else
        ans = 1 + a[a.size() / 2].first;
  } else {
    ans = 0;
  }
  cout << ans;
  return 0;
}
