#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int l = 0, r = s.size() - 1, ans = 3;
  while (l < r && s[l] == s[r] && ans >= 3) {
    char ch = s[l];
    ans = 0;
    while (s[l] == ch) ++l, ++ans;
    while (s[r] == ch && r >= l) --r, ++ans;
  }
  if (l > r && ans >= 2)
    cout << ans + 1;
  else
    cout << 0;
  return 0;
}
