#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  vector<pair<char, int>> a;
  for (int i = 0; i < n; i++) {
    int cnt = 1;
    for (int j = i; j < n; j++) {
      if (s[j] == s[j + 1]) {
        cnt++;
        i++;
      } else {
        break;
      }
    }
    a.push_back(make_pair(s[i], cnt));
  }
  for (int i = 0, j = a.size() - 1; j > i; i++, j--) {
    if (a[i].first != a[j].first) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i].second + a[j].second < 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (a[a.size() / 2].second + 1 < 3) {
    cout << 0 << endl;
  } else {
    cout << a[a.size() / 2].second + 1 << endl;
  }
  return 0;
}
