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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
#include<math.h>
#define MAX_N 100000
using namespace std;

int s[MAX_N];
int n=0;

int chk(int x){
 int a[n];
 for (int i=0;i<n;i++) a[i]=s[i];
 int i=x-1;
 /*while (i+x<=n&&i>=0){
  if (a[i]==1){
   for (int j=0;j<x;j++){
    if (a[i+j]==0) a[i+j]=1;
    else if (a[i+j]==1) a[i+j]=0;
   }
  }
   
  for (int j=0;j<n;j++) cout <<a[j];
 cout <<endl;
  i--;
 }*/
 int y=a[0],c=0;
 for (int k=0;k+x-1<n;k++) {
  //cout <<a[k]<<" "<<k<<endl;
  if (y!=a[k]) {y=a[k]; c++;}
 }
 //cout <<"c="<<c<<endl;
 int res=1;
 for (int k=n-x;k<x;k++)  {res*=(a[0]==((a[k]+c%2)%2)); /*cout <<"k="<<k<<endl;*/}

 
 return res;
}
  


int main(){
 char S[MAX_N];
 while (cin >>S[n]) {
  if (S[n]=='0') s[n]=0;
  else if (S[n]=='1') s[n]=1;
  n++;
 }
 

 /*for (int i=0;i<n;i++) cout <<s[i];
 cout <<endl;*/

 int i=0,j=0,k=0;
 while (s[i]==1&&i<n) i++;
 if (i==n) k=n;
 while (s[i+j]==0&&i+j<n) j++;
 k=j;
 j--;
 //右方向
 int r=0,rk=j+1;
 while(s[i+j+r+1]==1&&i+j+r<n) r++;
 if (i+j+r+k<n) rk+=r;
 rk=max(rk,r);
 k+=max(0,n-k-1);
 
 //左方向
 int l=0; 
 while (s[i-l-1]==1&&i-l>=0) l++;
 if (i-l-k>=0) k+=l;
  
 int a=n/2,b=n,c=(a+b)/2;
 while (b-a>1){
  //printf("a,b=%d,%d\n",a,b);
  c=(a+b)/2;
  if (chk(c)) a=c;
  else b=c;
 }
  cout <<a<<endl;






 /*printf("%d %d %d %d\n",i,j,r,l);
 cout <<k<<endl;
 cout <<max(j+1,max((n-1-i)/2+1,l))<<endl;*/
}