#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, -1, 0, 1};
const int drr[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dcc[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int i = 0; i < ((int)((t).size())); i++) s << t[i] << " ";
  return s;
}
class UnionFind {
 private:
  vector<int> rank, p;

 public:
  UnionFind(int n) {
    for (int i = 0; i < n; i++) p.push_back(i);
    rank.assign(n, 0);
  }
  int findSet(int s) { return (p[s] == s) ? s : (p[s] = findSet(p[s])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (isSameSet(i, j)) return;
    int x = findSet(i), y = findSet(j);
    if (rank[x] > rank[y])
      p[y] = x;
    else {
      p[x] = y;
      if (rank[x] == rank[y]) rank[y]++;
    }
  }
};
bool fcomp(double A, double B) {
  double EPSILON = numeric_limits<double>::epsilon();
  double diff = A - B;
  return (diff < EPSILON) && (-diff < EPSILON);
}
double x_y(int x1, int y1, int x2, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<pair<int, int> > segs;
  for (int i = 0; i < n; i++) {
    int j = i, ct = 0;
    while (j < n && s[j] == s[i]) {
      ct++;
      j++;
    }
    i = j - 1;
    segs.push_back(make_pair(ct, s[i] - 'A'));
  }
  int sz = segs.size();
  if (sz % 2 == 0) {
    printf("0");
    return 0;
  }
  int id = (sz - 1) / 2;
  int na = 0, diff = 1;
  if (segs[id].first + 1 < 3) na = 1;
  while (id - diff >= 0) {
    int i1 = id - diff, i2 = id + diff;
    if (segs[i1].second != segs[i2].second) na = 1;
    if (segs[i1].first + segs[i2].first < 3) na = 1;
    diff++;
  }
  if (na)
    printf("0");
  else
    printf("%d", segs[id].first + 1);
  return 0;
}
