#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    string s, k, p;
    long long i, cnt = 0;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
      if (s[i] != s[i + 1]) k += s[i];
    }
    for (i = s.size() - 1; i > 0; i--) {
      if (s[i] != s[i - 1]) p += s[i];
    }
    p += s[0];
    vector<long long> a;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == s[i + 1]) {
        cnt++;
      } else {
        a.push_back(cnt + 1);
        cnt = 0;
      }
    }
    long long store = a.size(), save = 0;
    for (i = 0; i < store; i++) {
      if (a[i] + a[store - i - 1] < 3) save++;
    }
    if (s[0] == s[s.size() - 1] && save == 0 && k == p)
      cout << a[store / 2] + 1;
    else
      cout << "0";
    cout << "\n";
  }
  return 0;
}
