#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) {
      ans = ((ans % 1000000007) * (a % 1000000007)) % 1000000007;
    }
    a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
    b = b >> 1;
  }
  return ans;
}
long long int powe(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) {
      ans = a * ans;
    }
    a = a * a;
    b = b >> 1;
  }
  return ans;
}
void solve() {
  string s;
  cin >> s;
  vector<pair<char, long long int> > v;
  for (int i = 0; i < s.length(); i++) {
    long long int curlen = 1;
    while (i < s.length() - 1 && s[i + 1] == s[i]) {
      curlen++;
      i++;
    }
    v.push_back({s[i], curlen});
  }
  if (v.size() % 2 == 0) {
    cout << 0 << endl;
  } else {
    int i = 0;
    for (i = 0; i < v.size() / 2; i++) {
      if (v[i].first == v[v.size() - 1 - i].first &&
          v[i].second + v[v.size() - 1 - i].second >= 3) {
      } else {
        cout << 0 << endl;
        return;
      }
    }
    if (v[v.size() / 2].second >= 2)
      cout << v[v.size() / 2].second + 1 << endl;
    else
      cout << 0 << endl;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t > 0) {
    solve();
    t--;
  }
}
