#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e9 + 7;
struct Point {
  long long int x, y;
};
Point p0;
void swap(Point &p1, Point &p2) {
  Point tmp = p1;
  p1 = p2;
  p2 = tmp;
}
long long int dist(Point &p1, Point &p2) {
  return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
long long int orientation(Point p, Point q, Point r) {
  long long int val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  if (val == 0) return 0;
  return (val > 0) ? 1 : 2;
}
int compare(const void *vp1, const void *vp2) {
  Point *p1 = (Point *)vp1;
  Point *p2 = (Point *)vp2;
  long long int o = orientation(p0, *p1, *p2);
  if (o == 0) return (dist(p0, *p2) >= dist(p0, *p1)) ? -1 : 1;
  return (o == 2) ? -1 : 1;
}
void pCp(Point points[], long long int n) {
  int ymin = points[0].y, min = 0;
  for (int i = 1; i < n; i++) {
    int y = points[i].y;
    if ((y < ymin) || (ymin == y && points[i].x < points[min].x))
      ymin = points[i].y, min = i;
  }
  swap(points[0], points[min]);
  p0 = points[0];
  qsort(&points[1], n - 1, sizeof(Point), compare);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string second;
  cin >> second;
  deque<pair<char, long long int> > de;
  char c = '!';
  long long int cnt = 0;
  for (long long int i = 0; i < second.size(); ++i) {
    if (second[i] != c) {
      if (c != '!') de.push_back({c, cnt});
      c = second[i];
      cnt = 1;
    } else
      cnt++;
  }
  de.push_back({c, cnt});
  while (de.size()) {
    pair<char, long long int> p1, p2;
    p1 = de.front();
    p2 = de.back();
    if (de.size() == 1) {
      if (p1.second < 2)
        return cout << 0, 0;
      else
        return cout << p1.second + 1, 0;
    }
    if (p1.first != p2.first)
      return cout << 0, 0;
    else if (p1.second + p2.second < 3)
      return cout << 0, 0;
    else {
      de.pop_front();
      if (de.size()) de.pop_back();
    }
  }
  cout << 0;
  return 0;
}
