Problem:
Score : 500 points

Problem Statement

You are given a string S consisting of 0 and 1.
Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.

Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.

Constraints

1\leq |S|\leq 10^5

S_i(1\leq i\leq N) is either 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.

Sample Input 1

010

Sample Output 1

2

We can turn all the characters of S into 0 by the following operations:

Perform the operation on the segment S[1,3] with length 3. S is now 101.

Perform the operation on the segment S[1,2] with length 2. S is now 011.

Perform the operation on the segment S[2,3] with length 2. S is now 000.

Sample Input 2

100000000

Sample Output 2

8

Sample Input 3

00001111

Sample Output 3

4

Solution in C++14 (Clang 3.8.0) (judge verdict: Wrong Answer)

#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, weight;
};
typedef vector<vector<Edge>> Graph;

template<class T, class OP, class PROP>
class Lazy_Segment_Tree {//0-indexed 半開
public:
	vector<T> data, lazy;
	vector<bool> isupd;
	int n;
	Lazy_Segment_Tree() {}
	void init(int a) {
		n = 1;
		while (n < a) n *= 2;
		data.resize(n * 2 - 1);
		lazy.resize(n * 2 - 1);
		isupd.resize(n * 2 - 1);
	}

	void prop(int num, int s) {
		if (isupd[num]) {
			data[num] = PROP()(data[num], lazy[num], 1, s);
			if (num < n - 1) {
				lazy[num * 2 + 1] = PROP()(lazy[num * 2 + 1], lazy[num]);
				lazy[num * 2 + 2] = PROP()(lazy[num * 2 + 2], lazy[num]);
				isupd[num * 2 + 1] = 1;
				isupd[num * 2 + 2] = 1;
			}
			lazy[num] = T();
			isupd[num] = 0;
		}
	}
	void op(int a, int b, T v, int num = 0, int base = 1) {
		int l = (num + 1 - base) * (n / base), r = l + n / base;
		prop(num, r - l);
		if (a == l && b == r) {
			isupd[num] = 1;
			lazy[num] = PROP()(lazy[num], v);
			prop(num, r - l);
		}
		else {
			int nr = (l + r) / 2;
			if (nr > a) op(a, min(b, nr), v, num * 2 + 1, base * 2);
			if (nr < b) op(max(a, nr), b, v, num * 2 + 2, base * 2);
			prop(num * 2 + 1, (r - l) / 2), prop(num * 2 + 2, (r - l) / 2);
			data[num] = OP()(data[num * 2 + 1], data[num * 2 + 2]);
		}
	}

	T query(int a, int b, int num = 0, int base = 1) {
		int l = (num + 1 - base) * (n / base), r = l + n / base;

		prop(num, r - l);

		if (a == l && b == r)
			return data[num];
		else {
			int nr = (l + r) / 2;
			T ret = T();
			if (nr > a) ret = OP()(ret, query(a, min(b, nr), num * 2 + 1, base * 2));
			if (nr < b) ret = OP()(ret, query(max(a, nr), b, num * 2 + 2, base * 2));
			return ret;
		}
	}
};


template<class T>
class ADD {
public:
	T operator ()(const T a, const T b, const int ra = 1, int rb = 1) {
		return a*ra + b*rb;
	}
};

template<class T>
class UPD {
public:
	T operator ()(const T a, const T b, const int ra = 1, int rb = 1) {
		return b;
	}
};

template<class T>
class RMQ {
public:
	T operator ()(const T a, const T b) {
		return max(a, b);
	}
};
template<class T>
class SUM {
public:
	T operator ()(const T a, const T b) {
		return a + b;
	}
};

struct N {
public:
	int num;
	N(int num) : num(num) {}
	N() :num(INT_MIN/2) {}
	N operator + (const N obj) const {
		return N(obj.num + num);
	}
	N operator * (const N obj) const {
		return N(obj.num * num);
	}
	bool operator < (const N obj)const {
		return obj.num > num;
	}
};


int solve(string str) {
	vector<pii> parse;

	if (str[0] == '1' && str[str.length() - 1] == '1') return -1;

	char cur = str[0];
	int cou = 0;
	REP(i, str.length()) {
		if (str[i] == cur) {
			cou++;
		}
		else {
			parse.push_back({cur - '0', cou});
			cou = 1;
			cur = str[i];
		}
	}
	parse.push_back({ cur - '0', cou });
	int ret = 0;
	if (str[0] == '0' && str[str.length() - 1] == '0') {
		int rin = INT_MAX;
		int sum = 0;
		REP(i, parse.size()) {
			if (parse[i].first == 1) {
				int hasamu, kasaneru;
				hasamu = min(sum + parse[i].second, (int)str.length() - sum);
				kasaneru = max(sum, (int)str.length() - sum - parse[i].second);

				rin =max(hasamu,kasaneru);
			}

			sum += parse[i].second;
		}
		ret = min(ret,rin);
	}
	else if (str[0] == '0') {
		ret = max(ret,parse[0].second);
	}
	else if (str[str.length() - 1] == '0') {
		ret = max(ret, parse[parse.size() - 1].second);
	}
	return ret;
}

int main(void) {
	string str;
	cin >> str;

	int ans = -1;

	ans = max(ans, solve(str));

	for (auto &itr : str) {
		if (itr == '0')
			itr = '1';
		else
		{
			itr = '0';
		}
	}
	ans = max(ans, solve(str));

	cout << ans%str.length() << endl;

	return 0;
}