#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long n = s.length();
  long long l = 0;
  long long r = n - 1;
  long long cnt = 3;
  while (l < r && s[l] == s[r] && cnt >= 3) {
    cnt = 0;
    char c = s[l];
    while (s[l] == c) {
      l++;
      cnt++;
    }
    while (s[r] == c && r >= l) {
      r--;
      cnt++;
    }
  }
  if (l > r) {
    if (cnt >= 2)
      cout << cnt + 1;
    else
      cout << 0;
  } else
    cout << 0;
  return 0;
}
