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 (Python):
S = input()
ans = len(S)
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        ans = min(ans, max(i+1, len(S)-i-1))

print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**6)

s = list(str(input()))

max_ = len(s)
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        left = i+1
        right = len(s)-left
        
        tmp = max(left, right)

        max_ = min(max_, tmp)
print(max_)

Solution (Python):
S = list(input())
l = len(S)
S1 = S[:l//2][::-1]
S2 = S[l-l//2:]
ans = (l+1)//2
c = S[l//2]
for i in range(l//2):
    if S1[i] == c and S2[i] == c:
        ans += 1
    else:
        break
print(ans)

Solution (Python):
def main():
    S = input()
    l = len(S)
    ans = l
    
    for i, s in enumerate(S[1:]):
        if s != S[i]:
            ans = min(ans, max(i+1, l-1-i))
    print(ans)
    
main()

Solution (Python):
s=input()
inf=10**10
t=inf

for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        t=min(t,max(i,len(s)-i))

if t==inf:
    print(len(s))
else:
    print(t)

Solution (Python):
s=input()
now=len(s)
for i in range(len(s)-1):
	if s[i]!=s[i+1]:
		now=min(now,max(i+1,len(s)-i-1))
print(now)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]



def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





S = S()
N = len(S)
if N == 1:
  print(1)
  exit()
if N%2:
  c = S[N//2]
  l,r = N//2-1,N//2+1
  ans = N//2+1
  while l>=0 and c == S[l] == S[r]:
    ans += 1
    l -= 1
    r += 1
  print(ans)
else:
  ans = N//2
  l,r = N//2-1,N//2
  while l>=0 and S[l] == S[r] == S[l+1]:
    ans += 1
    l -= 1
    r += 1
  print(ans)

Solution (Python):
S = input()
N = len(S)
ans = N

for n in range(N-1):
  if S[n+1]!=S[n]:   
    ans = min(ans,max(n+1,N-n-1))

print(ans)

Solution (Python):
S = list(input())
lenS = len(S)
S = S + ['.']
K = lenS
i = 0
ps = S[0]
for s in S:
    if s != ps:
        K = min(K, max(i, lenS-i))
        ps = s
    i += 1
print(K)

Solution (Python):
S = input()
cnt = [0]
now = '0'
for i in S:
    if now == i:
        cnt[-1] += 1
    else:
        cnt.append(1)
        now = i

ans = len(S)
sum = 0
for i in cnt:
    sum += i
    ans = min(ans, max(sum, len(S) - sum))
print(ans)

Solution (Python):
s = input()
n = len(s)

key = []
count = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    key.append(count)
    count = 1
  else:
    count += 1
key.append(count)

sum_key = sum(key)
ans = 10000000
for i in range(len(key)):
    if i != 0:
        key[i] += key[i-1]
    ans = min(ans, max(key[i], n-key[i]))
  

print(ans)

Solution (Python):
s=input();n=r=len(s)
for k in range(n-1):
  if s[k]!=s[k+1]: r=min(r,max(k+1,n-k-1))
print(r)

Solution (Python):
s=input();n=r=len(s)
for k in range(n-1):
  if s[k]!=s[k+1]:
    r=min(r,max(k+1,n-k-1))
print(r)

Solution (Python):
s = list(map(int, list(input())))
ans = len(s)
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans = min(ans, max(i+1, len(s)-i-1))
print(ans)

Solution (Python):
import sys

readline=sys.stdin.readline

s=list(readline().strip())
n=len(s)
f=n%2
mid=s[n//2]

for i in range(n//2):
  if s[n//2-i-1]!=mid or s[(n+1)//2+i]!=mid:
    print((n+1)//2+i)
    break
else:
  print(n)

Solution (Python):
S=input()
N=len(S)
cnt=N
for i in range(N-1):
  if S[i]!=S[i+1]:
    a=i+1
    b=N-a
    c=max(a,b)
    cnt=min(c,cnt)
print(cnt)

Solution (Python):
S=input()
l=len(S)
if l%2==1:
    m=S[l//2]
    c=1
    for i in range(l//2):
        if S[l//2-i-1]==m and S[l//2+i+1]==m:
            c+=2
        else:
            break
    ans=c+(l-c)//2
else:
    m1=S[l//2-1]
    m2=S[l//2]
    c=0
    if m1==m2:
        c=2
        for i in range(l//2-1):
            if S[l//2-i-2]==m1 and S[l//2+i+1]==m1:
                c+=2
            else:
                break
    ans=c+(l-c)//2
print(ans)

Solution (Python):
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  

S = LI2()
N = len(S)

def f(n):  
    for i in range(N-n,n):
        if S[i] != S[n-1]:
            return False
    return True

left,right = (len(S)+1)//2,len(S)+1
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        left = mid
    else:
        right = mid
print(left)

Solution (Python):
S=input()
n=len(S)
ans=n
for i in range(n-1):
  if S[i] != S[i+1]:
    ans=min(ans, max(i+1, n-i-1))

print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





S = input()
N = len(S)
ans = N

for i in range(1, N):
  if S[i] != S[i - 1]:
    now = max(i, N - i)
    ans = min(ans, now)

print(ans)

Solution (Python):

S = str(input())


N  =len(S)
ans = N
for i in range(1, N):
  if S[i] != S[i - 1]:
    now = max(i, N - i)
    ans = min(ans, now)

print(ans)

Solution (Python):
S = list(input())
C = len(S)
for i in range(len(S) - 1):
    if S[i] != S[i + 1]:
        c = max(i + 1, len(S) - i - 1)
        C = min(C, c)
print(C)

Solution (Python):
I = input()

n     = len(I)
left  = 0
right = n - 1

block_left_index  = 0
block_right_index = n






while left < right:
    if I[left] != I[left+1]:
        block_left_index = left+1
    if I[right] != I[right-1]:
        block_right_index = right
    left  += 1
    right -= 1

ans = min(n-block_left_index, block_right_index)
print(ans, flush=True)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    """
    備忘録用に自分のコードの解説。
    まずすぐにKの値を決め打ち二分探索することを思いつく。
    なので任意のKに対して、K文字以上の連続する区間を何回かフリップしてSを"000...0"にできるか判定できれば良い。

    ここで、Sの文字を0-indexedで添え字づけした時にK文字目以降は任意の１桁をフリップできることに気づく。
    というのも例えばm文字目(K <= m)をフリップしたければ[0, m-1], [0, m]の２区間をフリップすれば良い。
    同様に末尾からも考えると、0以上(|S|-K)未満の任意の１桁も自由にフリップできる。

    これよりK=|S|//2の時は必ずSを"000...0"にできることがわかる。
    ではKがこれより大きい時はどうなるだろうか？
    この時自由にフリップができない区間S[(|S|-K):K]が出現する。
    そして2つ目の気づきとして、この区間はどんな区間長K以上のフリップをかけても必ず全体のビットが反転する！

    以上より
        「区間長K以上のフリップをかけてSを"000...0"にできる」
         = 「中央区間S[(|S|-K):K]のビットが全て等しい」
    が結論となる。
    """
    S = input()
    N = len(S)
    if S == '1' * N or S == '0' * N:
        print(N)
        return
    left = N // 2
    right = N
    while right - left > 1:
        mid = (left + right) // 2
        if S[(N - mid):mid] == '1' * (2 * mid - N) or S[(N - mid):mid] == '0' * (2 * mid - N):
            left = mid
        else:
            right = mid
    print(left)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    N = len(S)
    if S == '1' * N or S == '0' * N:
        print(N)
        return
    left = N // 2
    right = N
    while right - left > 1:
        mid = (left + right) // 2
        if S[(N - mid):mid] == '1' * (2 * mid - N) or S[(N - mid):mid] == '0' * (2 * mid - N):
            left = mid
        else:
            right = mid
    print(left)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    l = len(s)
    ans = l
    for i in range(1, l):
        if s[i] != s[i - 1]:
            ans = min(ans, max(l - i, i))

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
if len(S)==1: print(1);exit()
ans = len(S)
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        ans = min(ans,max(i,len(S)-i))

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

S = readline().rstrip()

ans = len(S)
for i in range(1,len(S)):
  if S[i] != S[i - 1]:
    longer = max(i, len(S) - i)
    if ans > longer:
      ans = longer
      
print(ans)

Solution (Python):
S = input()
L = len(S)
now = S[0]
ok = True
ans = 10**18
for i in range(1, L):
    if S[i] != now:
        now = S[i]
        ans = min(ans, max(i, L-i))
        ok = False
if ok:
    print(L)
else:
    print(ans)

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    

    s = input()
    n = len(s)
    ans = n
    for i in range(1, n):
        if s[i] != s[i-1]:
            ans = min(ans, max(i, n - i))
    print(ans)

    

if __name__ == "__main__":
    main()

Solution (Python):
s=input()
cs=[]
cnt=1
pre=s[0]
for si in s[1:]:
  if si==pre:
    cnt+=1
  else:
    cs.append(cnt)
    pre=si
    cnt=1
cs.append(cnt)
n=len(s)
ans1=n
merge=0
no_merge=n
for i in range(len(cs)):
  merge+=cs[i]
  no_merge-=cs[i]
  tmp=max(merge,no_merge)
  ans1=min(ans1,tmp)
cs.reverse()
ans2=n
merge=0
no_merge=n
for i in range(len(cs)):
  merge+=cs[i]
  no_merge-=cs[i]
  tmp=max(merge,no_merge)
  ans2=min(ans2,tmp)
print(max(ans1,ans2))

Solution (Python):
S = input()

n = len(S)
a = n
for i in range(n-1):
    if S[i] != S[i+1]:
        a = min(a, max(i+1, n-i-1))

print(a)

Solution (Python):
S = input()
n = len(S)    
K = n
for k in range(n-1):
    if S[k] != S[k+1]:
        K = min(K, max(k+1, n-k-1))
print(K)

Solution (Python):


def check(s, n, k):
    l = n - k
    r = k

    for c in s[l + 1:r]:
        if c != s[l]:
            return False
    
    return True


def submit():
    s = input()
    n = len(s)

    if check(s, n, n):
        print(n)
        return

    l = 1
    r = n
    while l + 1 < r:
        m = (l + r) // 2
        if check(s, n, m):
            l = m
        else:
            r = m
    print(l)
    


if __name__ == "__main__":
    submit()

Solution (Python):
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1
m = n-1

while len(res) >1:
    resu = min(resu,max(res[0],m-res[0]))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)

Solution (Python):
S = list(input())

def check(x):
    
    for y in S[len(S)-x:x]:
        if y != S[len(S)-x]: break
    else:
        return True
    return False

def bisect(l,r):
    if r - l == 1: return l
    mid = (l+r) // 2
    if check(mid) == False:
        return bisect(l,mid)
    else:
        return bisect(mid,r)
print(bisect(0,len(S)+1))

Solution (Python):
import sys
import math
input = sys.stdin.readline

s = input().strip()
n = len(s)
a = [ord(s[0]) - ord('0')]
for i in range(n - 1):
    if s[i] == s[i + 1]:
        a.append(0)
    else:
        a.append(1)
a.append(ord(s[n - 1]) - ord('0'))
ans = n
for i in range(len(a)):
    if a[i] == 1:
        ans = min(ans, max(n - i, i))
if sum(a) % 2 == 0:
    print(ans)
else:
    print(-1)

Solution (Python):
S = [0] + list(map(int, list(input())))
N = len(S) - 1

def change(s, c):
  if c == 0:
    return s
  else:
    return 1 - s

def check(k):
  count = [0] * (N+1)
  T = S.copy()
  for i in range(1, N+1):
    c = count[i-1]
    s = change(S[i], c)
    if i < N - k + 2:
      T[i] = 0
      if s == 1:
        count[i] = (c + 1) % 2
      else:
        count[i] = c        
    else:
      T[i] = s
      count[i] = c      
  n = 0
  for t in T[1:]:
    if t == 1:
      break
    n += 1
  return n >= k


left = 1 
right = N
while left + 1 < right:
  mid = (left + right) // 2
  if check(mid):
    left = mid
  else:
    right = mid

if right == N and check(N):
  print(N)
else:
  print(left)

Solution (Python):
def main():
    S = input()
    N = len(S)
    ans = N
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            ans = min([ans, max([i + 1, N - (i + 1)])])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def rle(s):
    
    before_c = s[0]
    ret = list()
    cnt = 0
    for c in s:
        if before_c == c:
            cnt += 1
        else:
            ret.append(cnt)
            before_c = c
            cnt = 1
    if cnt > 0:
        ret.append(cnt)
    return ret


def main():
    S = input()
    N = len(S)
    seq_cnt = rle(S)
    if len(seq_cnt) == 1:
        print(seq_cnt[0])
        return
    if len(seq_cnt) == 2:
        print(max(seq_cnt))
        return
    
    cumsum_seq_cnt = [0 for _ in range(len(seq_cnt))]
    rev_cumsum_seq_cnt = [0 for _ in range(len(seq_cnt))]
    cumsum_seq_cnt[0] = seq_cnt[0]
    rev_cumsum_seq_cnt[0] = seq_cnt[-1]
    for i in range(1, len(seq_cnt)):
        cumsum_seq_cnt[i] = cumsum_seq_cnt[i-1] + seq_cnt[i]
        rev_cumsum_seq_cnt[i] = rev_cumsum_seq_cnt[i-1] + seq_cnt[-1-i]
    
    max_k = cumsum_seq_cnt[0]
    rev_max_k= rev_cumsum_seq_cnt[0]
    for i in range(1, len(seq_cnt)):
        k = cumsum_seq_cnt[i]
        if k <= N - cumsum_seq_cnt[i-1]:
            max_k = k
        rev_k = rev_cumsum_seq_cnt[i]
        if rev_k <= N - rev_cumsum_seq_cnt[i-1]:
            rev_max_k = rev_k
    print(max([max_k, rev_max_k]))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=list(map(int,list(input())))
    N=len(S)
    if N%2==0:
        left=N//2-1
        right=N//2
        ans=N//2
        if S[left]==S[right]:
            x=S[left]
            while left-1>=0 and S[left-1]==x:
                left-=1
            while right+1<N and S[right+1]==x:
                right+=1
            ans+=min(N//2-left,right-N//2+1)
    else:
        left=N//2
        right=N//2
        x=S[N//2]
        ans=N//2+1
        if left-1>=0 and S[left-1]==x:
            while left-1>=0 and S[left-1]==x:
                left-=1
        if right+1<N and S[right+1]==x:
            while right+1<N and S[right+1]==x:
                right+=1
        ans+=min(N//2-left,right-N//2)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
s = list(input())

ans = float("INF")
if len(s) == 1:
    print(1)
    exit()
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        c = max(i+1,len(s)-i-1)
    
        ans = min(ans,c)
if ans == float("INF"):
    print(len(s))
else:

    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000000)

def main():
    S = input()
    N = len(S)
    ans = 0
    before = 0
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            ans = max(ans,min(N - before,i + 1))
            before = i + 1
    ans = max(ans,N - before)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
n = len(s)
ans = n
s1 = s.count('1')
i = 0
while s1 != 0 and s1 != n:
  s1 -= int(s[i]) + int(s[i + n - 1])
  if n == 1:
    s1 += int(s[i])
  n -= 2
  ans -= 1
  i += 1
print(ans)

Solution (Python):
def main():
    s = input()
    ans = len(s)
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            tmp = max(i+1, len(s)-i-1)
            ans = min(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
s = input()
len_s = len(s)
ans = len_s // 2
center = ans
b = s[ans]
if len_s % 2:
  for i in range(center+1):
    if s[center-i] == s[center+i] == b:
      ans += 1
    else:
      break
else:
  for i in range(center):
    if s[center-1-i] == s[center+i] == b:
      ans += 1
    else:
      break
print(ans)

Solution (Python):
s = list(input())
n = len(s)
if n % 2 == 0:
    for i in range(n//2):
        a = s[n // 2]
        if s[n // 2 - 1 - i] != a or s[n // 2 + i] != a:
            print(n // 2 + i)
            exit()
else:
    for i in range(1, (n - 1) // 2 + 1):
        b = s[(n-1)//2]
        if s[(n - 1) // 2 - i] != b or s[(n - 1) // 2 + i] != b:
            print((n-1)//2+i)
            exit()
print(n)

Solution (Python):
s=input()
ans=len(s)
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    ans=min(ans,max(i+1,len(s)-i-1))
print(ans)

Solution (Python):
s = input()
n = len(s)

l = 0
r = n//2 + 1

while r - l > 1:
    m = l + (r-l)//2
    d = n//2 - m
    if s[d:n-d].count("0") == 0 or s[d:n-d].count("1") == 0:
        l = m
    else:
        r = m

if n % 2 == 0:
    print(n//2+l)
else:
    print(n//2+l+1)

Solution (Python):
slist=list(map(int,list(input())))
len_s=len(slist)

min_answer=len_s
for i in range(1,len_s):
  if slist[i-1]!=slist[i]:
    min_answer=min(min_answer,max(i,len_s-i))
    

print(min_answer)

Solution (Python):
"""
互いに異なる隣り合う要素を揃えることに着目する

_________10___
↓
_________00___
(左端から1のところまでを反転)

_________01___
↓
_________11___
(左端から0のところまでを反転)
↓
_________00___
(全体を反転)

K>=max(k, n-k)+1だとどのような区間を取っても
01, 10を揃えることができない
"""

import sys
input = sys.stdin.readline

S = input()[:-1]

if S in ['0'*len(S), '1'*len(S)]:
    print(len(S))
    exit()

T = 10**10

for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        T = min(T, max(i+1, len(S)-i-1))

print(T)

Solution (Python):
S=input()
N=len(S)

b=[int(S[i]) for i in range(N)]
for i in range(1,N):
    b[i]+=b[i-1]
black=[0 for i in range(0,N+1)]
for i in range(0,N):
    black[i+1]=b[i]

def condition(K):
    if 2*K-1<N:
        return True
    else:
        if black[K]-black[N-K]==0 or black[K]-black[N-K]==2*K-N:
            return True
        else:
            return False

start=1
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test

if condition(end):
    print(end)
else:
    print(start)

Solution (Python):

def main():
    S = input()
    r = len(S)
    if S.count('0') == r:
        return r
    if S.count('1') == r:
        return r
    N = len(S)
    one = S[0] == '1'
    c = 0
    for i in range(N):
        if (S[i] == '1' and one) or (S[i] == '0' and not one):
            continue
        r = min(r, max(i, N-i))
        one = S[i] == '1'
    return r
print(main())

Solution (Python):
def main():
    S = input()
    A = []
    i, t = 1, S[0]
    for s in S[1:]:
        if s != t:
            A.append(i)
            i = 1
            t = s
        else:
            i += 1
    A.append(i)

    m, l  = len(S), 0
    for a in A:
        t = max(l + a, len(S) - l - a)
        m = min(m, t)
        l += a
    return m

print(main())

Solution (Python):
S = input()
N = len(S)
res = N
for i in range(N - 1):
    if S[i] != S[i + 1]:
        res = min(res, max(i + 1, N - (i + 1)))
print(res)

Solution (Python):


import io
import sys
import math

data = input()
n = len(data)
ans = n
for i in range(n - 1):
    if data[i] != data[i + 1]:
        ans = min(ans, max(i + 1, n - i - 1))
print(ans)

Solution (Python):
s = input()

half = (len(s)-1)//2

ans = half+1
c = s[half]
for x,y in zip(s[half+1:],s[half-(len(s)%2==1)::-1]):
    if x==c and y==c:
        ans += 1
    else:
        break
print(ans)

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product

def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
ls=len(s)
kijun=s[ls//2]
if ls%2==0:
    tmp=0
    for i in range(ls//2):
        if kijun==s[ls//2+i]==s[ls//2-1-i]:
            tmp+=1
        else:
            break
    print(ls//2+tmp)
else:
    tmp=1
    for i in range(ls//2):
        if kijun==s[ls//2+1+i]==s[ls//2-1-i]:
            tmp+=1
        else:
            break
    print(ls//2+tmp)

Solution (Python):
S = input()
MIN = 10 ** 8
flag = 1
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        flag = 0
        MIN = min(MIN, max(i + 1, len(S) - i - 1))
if flag:
    MIN = len(S)
print(MIN)

Solution (Python):
s = input()

n = len(s)
ans = n
for i in range(1, n):
    if s[i - 1] != s[i]:
        
        
        ans = min(ans, max(i, n - i))

print(ans)

Solution (Python):
s = [int(i) for i in input()]
n = len(s)
ans = n
for i in range(n-1):
  if s[i] != s[i+1]:
    ans = min(ans, max(i+1, n-i-1))
print(ans)

Solution (Python):
s = list(input())
l = len(s)
if l % 2 == 0:
    for i in range(l//2):
        a = s[l//2]
        if s[l//2 - 1 - i] != a or s[l//2 + i] != a:
            print(l//2 + i)
            exit()
else:
    for i in range(1, (l-1)//2 + 1):
        a = s[(l-1)//2]
        if s[(l-1)//2 - i] != a or s[(l-1)//2 + i] != a:
            print((l-1)//2 + i)
            exit()
print(l)

Solution (Python):

import sys


def solve(S: str):
    N = len(S)
    m = N
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            m = min(m, max(N - (i + 1), i + 1))
    print(m)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)


if __name__ == '__main__':
    main()

Solution (Python):
def find_cont(S):
    N=len(S)
    res=N
    for i in range(N-1):
        if S[i]!=S[i+1]:
            res=min([res,max(i+1,N-1-i)])
    return res
S=input()
print(find_cont(S))

Solution (Python):
s=input()
n=len(s)
ans=n
for i in range(n-1):
  if s[i+1]!=s[i]:   
    ans=min(ans,max(i+1,n-i-1))
print(ans)

Solution (Python):








s = input()

if len(s) % 2 == 0:
    number = s[len(s) // 2]
    other = s[len(s) // 2 - 1]
    p = len(s) // 2
    cnt = 0
    if number == other:
        cnt += 1
        for i in range(1, p):
            if s[p + i] == s[p - 1 - i] == number:
                cnt += 1
            else:
                break
    print(p + cnt)


else:
    number = s[len(s) // 2]
    cnt = 0
    p = len(s) // 2

    for i in range(1, len(s) // 2 + 1):
        if s[p - i] == s[p + i] == number:
            cnt += 1
        else:
            break
    print(p + 1 + cnt)

Solution (Python):
from collections import deque

x, y = deque(), deque()
s = deque(list(input()))
n = len(s)
m = s[n // 2]
ans = (n + 1) // 2
for _ in range((n + 1) // 2):
    x.appendleft(s.popleft())
for _ in range(n // 2):
    y.appendleft(s.pop())
if n % 2 == 1:
    x.popleft()
for i in range(n // 2):
    if x[i] == y[i] == m:
        ans += 1
    else:
        break
print(ans)

Solution (Python):



s=input()
l=len(s)

ans=1000000000000
for i in range(l-1):
    if s[i]!=s[i+1]:
        ne=max(i+1,l-i-1)
        ans=min(ans,ne)
if ans==1000000000000:
    print(l)
else:
    print(ans)

Solution (Python):
S = input()
N = len(S)
ans = N
for i in range(N - 1):
    if S[i] != S[i + 1]:
        ans = min(ans, max(i + 1, N - (i + 1)))
print(ans)

Solution (Python):
import sys

 
def main():
    s = input()
    l = len(s)
    if "0" not in s or "1" not in s:
        print(l)
    else:
        ans = 10**6
        for i in range(l-1):
            if s[i] != s[i+1]:
                ans = min(ans,max(i+1,l-i-1))
        print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
S = input()
l = len(S)
ans = l
"""
if len(set(list(S))) == 1 and S[0] == "0":
    print(0)
    exit()
"""
for i in range(l-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(l-i-1,i+1))
print(ans)

Solution (Python):
import math
def f(s):
    if len(s)%2==0: p=len(s)//2-1
    else: p=len(s)//2
    
    q=p
    while  q<len(s) and s[p]==s[q]:
        q+=1
    return q



s=input()
l=len(s)
ans=l
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans=min(ans, max(i+1,l-i-1) )
print(ans)

Solution (Python):
import math
def f(s):
    if len(s)%2==0: p=len(s)//2-1
    else: p=len(s)//2
    
    q=p
    while  q<len(s) and s[p]==s[q]:
        q+=1
    return q



s=input()

print(min(f(s),f(s[::-1])))

Solution (Python):
s = input()

l = len(s)
center = s[l // 2]
cnt = l % 2
for e1, e2 in zip(s[:l//2][::-1], s[l//2+l%2:]):
    if center == e1 == e2:
        cnt += 2
    else:
        break

ans = (l + cnt) // 2
print(ans)

Solution (Python):
s = input()

l = len(s)
ans = l
for i, (e1, e2) in enumerate(zip(s, s[1:]), 1):
    if e1 != e2:
        ans = min(ans, max(i, l - i))

print(ans)

Solution (Python):
S=input()
n=len(S)
if n%2:
    m=n//2
    t=S[m]
    for i in range(m):
        if S[m+i+1]!=t or S[m-i-1]!=t:
            a=m+i+1
            break
    else:
        a=n
else:
    m=n//2
    t=S[m]
    for i in range(m):
        if S[m+i]!=t or S[m-i-1]!=t:
            a=m+i
            break
    else:
        a=n
print(a)

Solution (Python):
s=list(input())
l=[len(s)]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    l.append(max(i+1,len(s)-i-1))
print(min(l))

Solution (Python):
s = str(input())
n = len(s)

if n == 1:
    print(1)
    exit()

maxs = []
for i in range(n-1):
    if s[i] != s[i+1]:
        maxs.append(max(i+1, n-i-1))

if maxs != []:
    print(min(maxs))
else:
    print(n)

Solution (Python):
s = str(input())
n = len(s)

if n == 1:
    print(1)
    exit()

maxs = []
for i in range(n-1):
    if s[i] != s[i+1]:
        maxs.append(max(i+1, n-i-1))

if maxs != []:
    print(min(maxs))
else:
    print(n)

Solution (Python):
from collections import deque

S=input()
N=len(S)

prev=S[0]
ans=N
temp=0

con=deque()

for i in range(N):
    if S[i]==prev:
        temp+=1
    else:
        con.append(temp)
        prev=S[i]
        temp=1
con.append(temp)       
        
        
    
while len(con)>2:
    a=con[0]
    b=con[-1]
    if b>=a:
        c=con.popleft()
        con[0]+=c
        ans=min(ans,N-a)
    else:
        c=con.pop()
        con[-1]+=c
        ans=min(ans,N-b)
    
    
    
if len(con)==2:
    ans=min(ans,max(con))
else:
    ans=N
    
    
print(ans)

Solution (Python):
def main():
  S = input()
  j = 0
  m = S[0]
  ls = []
  for i in range(len(S)):
    if m!=S[i]:
      ls.append(i-j)
      j = i
      m = S[i]
  ls.append(len(S)-j)
  N = len(ls)
  if N<3:
    print(max(ls))
  else:
    ans = float('inf')
    sls = [ls[0]]
    for i in range(1,N):
      sls += [sls[-1]+ls[i]]
    ans = min(max(sls[i], sls[-1]-sls[i]) for i in range(N-1))
    print(ans)

if __name__=='__main__':
  main()

Solution (Python):
S = input()
j = 0
m = S[0]
ls = []
for i in range(len(S)):
  if m!=S[i]:
    ls += [i-j]
    j = i
    m = S[i]
ls += [len(S)-j]
N = len(ls)
if N<3:
  print(max(ls))
else:
  ans = float('inf')
  sls = [ls[0]]
  for i in range(1,N):
    sls += [sls[-1]+ls[i]]
  for i in range(N-1):
    ans = min(ans,max(sls[i], sls[-1]-sls[i]))
  print(ans)

Solution (Python):
s=list(str(input()))
n=len(s)
ans=10**10
for i in range(n-1):
    if s[i]!=s[i+1]:
        ans=min(ans,max(i+1,n-i-1))

if ans==10**10:
    print(n)
else:
    print(ans)