#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
using namespace std;
void vok() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
}
int func(vector<int> &A, int n) {}
int main() {
  vok();
  int t = 1;
  while (t--) {
    int n, m, a, b, c, d, x, y, k;
    string A;
    cin >> A;
    n = A.size();
    int l = 0, r = n - 1;
    c = 3;
    while (l < r and A[l] == A[r] and c >= 3) {
      char ch = A[l];
      c = 0;
      while (A[l] == ch) l++, c++;
      while (A[r] == ch and r >= l) r--, c++;
    }
    if (l > r)
      cout << c + 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
