#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const int nmax = 1e5 + 10;
const int eps = 1e-8;
const long long infll = 1e15;
struct balls {
  int nos;
  char color;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<balls> v;
  balls temp;
  for (int i = 0; i < s.length(); i++) {
    if (i == 0) {
      temp.nos = 1;
      temp.color = s[i];
    } else {
      if (s[i] == s[i - 1])
        temp.nos++;
      else {
        v.push_back(temp);
        temp.nos = 1;
        temp.color = s[i];
      }
    }
  }
  v.push_back(temp);
  int n = v.size();
  if (n % 2 == 0 or v[n / 2].nos < 2) {
    cout << "0\n";
    return 0;
  }
  for (int i = 0, j = n - 1; i < n / 2; i++, j--) {
    if (v[i].color != v[j].color or v[i].nos + v[j].nos < 3) {
      cout << "0\n";
      return 0;
    }
  }
  cout << v[n / 2].nos + 1 << "\n";
  return 0;
}
