#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
vector<pii> st;
int main() {
  string str;
  cin >> str;
  st.emplace_back(str[0], 0);
  for (auto &x : str) {
    if (st.back().first != x) st.emplace_back(x, 0);
    st.back().second++;
  }
  for (int i = 0, j = st.size() - 1; i < j; i++, j--) {
    if (st[i].first != st[j].first || st[i].second + st[j].second < 3 ||
        i + 1 == j) {
      cout << 0 << endl;
      return 0;
    }
  }
  int mid = st.size() / 2;
  cout << (st[mid].second == 1 ? 0 : st[mid].second + 1) << endl;
}
