#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<pair<char, int>> colors;
  colors.push_back({s[0], 1});
  for (int i = 1; i < s.size(); i++)
    if (s[i] == s[i - 1])
      colors.back().second++;
    else
      colors.push_back({s[i], 1});
  int mid = colors.size() / 2;
  if (colors.size() % 2 != 1 || colors[mid].second == 1) {
    cout << 0;
    return 0;
  }
  for (int i = mid - 1; i >= 0; i--)
    if (colors[i].first != colors[colors.size() - i - 1].first ||
        colors[i].second + colors[colors.size() - i - 1].second < 3) {
      cout << 0;
      return 0;
    }
  cout << colors[mid].second + 1;
  return 0;
}
