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()
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
sys.setrecursionlimit(2147483647)
import math
from heapq import heappush, heappop, heapify

def solve(s):
  n = len(s)
  k = n
  for i in range(n-1):
    if s[i] != s[i+1]:
      k = min(k, max(i+1, n-i-1))
  return k

def main():
  s = input()
  ans = solve(s)
  print(ans)
  

if __name__=='__main__':
  main()

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

Solution (Python):
S = [int(x) for x in input()]
s = len(S)
ans = float('inf')
for i in range(s-1):
    if S[i] != S[i+1]:
        ans = min(ans, max(i+1, s-i-1))

if ans == float('inf'):
    ans = s
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    
    mod = 1000000007
    

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


if __name__ == "__main__":
    main()

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

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

n = len(s)

if len(set(list(s))) == 1:
    print(n)
    exit()

def is_ok(x):
    for i in range(n-x, x-1):
        if s[i] != s[i+1]:
            return False
    else:
        return True

l = 1
r = n
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        l = c
    else:
        r = c
print(l)

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-1-i))
print(ans)

Solution (Python):
def solve():
  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))
  return ans
print(solve())

Solution (Python):
s=input()
n=len(s)
i=n//2
while i<n and s[i]==s[n-1-i] and s[i]==s[n//2]:
  i+=1
print(i)

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(n-i-1, i+1))

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

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

S = readline().rstrip()
N = len(S)
ans = N
ans2 = N
for i in range(N):
    if S[i] == "1":
        ans = min(ans,max(N-i-1,i))
    else:
        ans2 = min(ans2,max(N-i-1,i))
print(max(ans,ans2))

Solution (Python):
S = str(input())
N = len(S)
ans = N//2

while ans < N:
  K = ans+1
  start = N-K
  end = K-1
  leng = end-start+1
  C = str(S[start:end+1])
  
  if C == "0"*leng or C == "1"*leng:
    ans += 1
  else:
    
    break
print(ans)

Solution (Python):
S = str(input())
N = len(S)
ans = N//2

while ans < N:
  K = ans+1
  start = N-K
  end = K-1
  leng = end-start+1
  C = str(S[start:end+1])
  
  if C == "0"*leng or C == "1"*leng:
    ans += 1
  else:
    
    break
print(ans)

Solution (Python):
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()

    n = len(s)
    if n&1:
        t = 1
        sf = n//2-1
        so = n//2+1
        ss = s[n//2]
        while sf >= 0:
            if s[so] == ss == s[sf]:
                t += 1
                sf -= 1
                so += 1
            else:
                break
        print(t+n//2)
    else:
        if s[n//2] == s[n//2-1]:
            ss = s[n//2]
            t = 1
            sf = n//2-2
            so = n//2+1
            while sf >= 0:
                if s[so] == ss == s[sf]:
                    t += 1
                    sf -= 1
                    so += 1
                else:
                    break
            print(n//2+t)
        else:
            print(n//2)


    return None

if __name__ == '__main__':
    main()

Solution (Python):
s = input()

if len(s) % 2 == 0:
    mid_l = len(s)//2 - 1
    mid_r = len(s)//2
    if s[mid_l] != s[mid_r]:
        print(len(s) // 2)
    else:
        mid_char = s[mid_l]
        for t in range(1, len(s)//2):
            if not (s[mid_l - t] == s[mid_r + t] == mid_char):
                print(mid_r+t)
                break
        else:
            print(len(s))
else:
    mid = len(s)//2
    mid_char = s[mid]
    for t in range(1, len(s)//2+1):
        if not (s[mid - t] == s[mid + t] == mid_char):
            print(mid+t)
            break
    else:
        print(len(s))

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()


S = [int(x == "1") for x in ins()]
N = len(S)


def check(k):
    assert k < N
    if 2 * k - 1 <= N:
        return True
    a = S[k - 1]
    return all(S[i] == a for i in range(N - k, k))


def solve():
    if all(x == 0 for x in S):
        return N
    if all(x == 1 for x in S):
        return N

    ok, ng = 1, N
    while ng - ok > 1:
        m = (ok + ng) // 2
        if check(m):
            ok = m
        else:
            ng = m
    return ok


print(solve())

Solution (Python):
mod = 10**9+7
import sys
import math
from collections import Counter, defaultdict, deque
import copy




















 








sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1


p2D = lambda x: print(*x, sep="\n")

def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())




def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

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

Solution (Python):
s=input()
ans=len(s)
length=len(s)
for i in range(len(s)-1):
    if (s[i]=="1" and s[i+1]=="0") or (s[i]=="0" and s[i+1]=="1"):
        maximum=max(i+1, length-i-1)
        ans=min(ans, maximum)
print(ans)

Solution (Python):
S = input()

ceil = lambda a, b: (a + b - 1) // b
x = len(S) // 2
x_num = S[x]
while x < len(S) and x_num == S[x] == S[len(S) - x - 1]:
    x += 1
print(x)

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

if n % 2 == 0:
    ans = n // 2
    tmp = set()
    x = n // 2 - 1
    for cnt in range(0, n // 2):
        tmp.add(s[x-cnt])
        tmp.add(s[x+1+cnt])
        if len(tmp) == 2:
            ans = cnt
            break

    print(ans + n // 2)

else:
    x = n // 2
    tmp = {s[x]}
    ans = n // 2 + 1
    for cnt in range(1, n // 2 + 1):
        tmp.add(s[x-cnt])
        tmp.add(s[x+cnt])
        if len(tmp) == 2:
            ans = cnt
            break
    print(ans + n // 2)

Solution (Python):


def main():
    from itertools import tee
    S = input()
    L = len(S)

    s1, s2 = tee(iter(S), 2)
    next(s2)

    k = L
    for i, (c1, c2) in enumerate(zip(s1, s2), start=1):
        if c1 != c2:
            t = max(i, L - i)
            if k > t:
                k = t
    print(k)


if __name__ == '__main__':
    main()

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

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

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

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


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

Solution (Python):

from queue import deque
def sub(s, k):
    tmp = 0
    q = deque()
    for c in s[:-k+1]:
        if (int(c)+tmp)%2:
            q.appendleft(1)
            tmp += 1
        else:
            q.appendleft(0)
        if len(q)>=k:
            tmp -= q.pop()
        print(q, tmp)
    for c in s[-k+1:]:
        if (int(c)+tmp)%2:
            return False
        tmp -= q.pop()
    return True
    
s = input()
n = len(s)
if n%2:
    m = n//2
    v = s[m]
    c = 0
    while m-c>=0 and m+c<=n-1:
        if s[m+c]==v and s[m-c]==v:
            c += 1
        else:
            break
    print((n + 2*c - 1) // 2)
else:
    m = n//2
    v = s[m]
    c = 0
    while m-1-c>=0 and m+c<=n-1:
        if s[m+c]==v and s[m-1-c]==v:
            c += 1
        else:
            break
    print((n+2*c)//2)

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

Solution (Python):
S = input()
l = len(S)
if l % 2 == 0:
    ans = l // 2
    after_half = l//2
    before_half = after_half - 1
    s = S[l//2]
    for i in range(l//2):
        if S[before_half] == S[after_half] and S[before_half] == s:
            ans += 1
            before_half -= 1
            after_half += 1
        else:
            break
if l % 2 == 1:
    ans = l // 2 
    after_half = l//2
    before_half = after_half
    s = S[l//2]
    for i in range(l//2 + 1):
        if S[before_half] == S[after_half] and S[before_half] == s:
            ans += 1
            before_half -= 1
            after_half += 1
        else:
            break

print(ans)

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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
ans = n

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

print(ans)

Solution (Python):
def main():
    import collections
    S = list(map(int, list(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)


main()

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

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

S = readline().rstrip().decode()
N = len(S)

def rui(a):
    ret = [0] * (len(a) + 1)
    for i in range(len(a)):
        ret[i + 1] = ret[i] + (1 if a[i] == '1' else 0)
    return ret
r = rui(S)



ok = 0
ng = N + 1

while ok + 1 < ng:
    med = (ng + ok) // 2
    
    le = N - med
    ri = med
    
    if le >= ri:
        ok = med
    else:
        ru = r[ri] - r[le]
        if ru == 0 or ru == ri - le:
            ok = med
        else:
            ng = med

print(ok)

Solution (Python):
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

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()
ans = 10**6
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        ans = min(ans,max(i+1,len(s)-i-1))
if ans ==10**6:
    print(len(s))
else:
    print(ans)

Solution (Python):
S = list(map(int, input()))
N = len(S)

def solve(c):
	cond = 0
	f = [0] * N
	if S[0] == 1:
		f[0] = 1
	cnt = 1
	for i in range(1,N-c+1):
		if i < c:
			f[i] = f[i-1]
			if (S[i] + f[i]) % 2 == 1:
				f[i] += 1
			cnt += 1

		if i >= c:
			f[i] = f[i-1] - f[i-c]
			if (S[i] + f[i]) % 2 == 1:
				f[i] += 1
			cnt += 1
		
		if cnt >= c:
			cond = 1
			break
	if cond == 0:
		for i in range(N-c+1,N):
			f[i] = f[i-1] - f[i-c]
			if (S[i] + f[i]) % 2 == 0:
				cnt += 1
			else:
				break

			if cnt >= c:
				cond = 1
				break

	return cond

def binary_search(s,f):
	if s == f:
		return s
	elif s+1 == f:
		if solve(f):
			return f
		else:
			return s

	c = (s+f)//2

	if solve(c):
		return binary_search(c,f)
	else:
		return binary_search(s,c)

print(binary_search(1,N))

Solution (Python):
s = input()
memo = []
pre, c = s[0], 0
for si in s:
    if si != pre:
        memo.append(c)
    c += 1
    pre = si
memo.append(c)

n = len(s)
ans = n
for mi in memo:
    ans = min(ans, max(mi, n - mi))
print(ans)

Solution (Python):



S = input()
N = len(S)

"""
全て0にできるような〜とあるが、全て1にしてから0にしてもいいので、どっちを目指してもいい

S = 1100001111 の時
S[1] != S[2]なので、そこの左か右でひっくり返す
左：0000001111 -> 1111110000 -> 0000000000 より、K=2
右：1111110000 -> 0000000000 よりK=6

1とか0とか実際の値は重要ではなく、どっちをひっくり返すか選択を迫られた時に、長い方をひっくり返すことで、答えの減少幅を小さくできるみたいなイメージ

"""

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
input = sys.stdin.readline
S = list(map(int, list(input())[: -1]))

def check(x):
  t = S + []
  for i in range(len(t) - x):
    t[i] = 0
    t[-1 - i] = 0
  if t.count(0) == len(t):
    return True
  for i in range(len(t) - x):
    t[i] = 1
    t[-1 - i] = 1
  if t.count(1) == len(t):
    return True
  return False

ok = 1
ng = len(S) + 1
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(ok)

Solution (Python):

from itertools import *








S=input()

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

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
n = len(s)
if n%2==0:
    k = k0 = n//2
    for i in range(k0):
        x = s[k0]
        if not (s[k0+i]==s[k0-1-i]==x):
            break
        k += 1
else:
    k0 = n//2
    k = k0+1
    x = s[k0]
    for i in range(1,k0+1):
        if not (s[k0+i]==s[k0-i]==x):
            break
        k += 1
print(k)

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

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

print(ans)

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

Solution (Python):
def main():
    
    S = input()
    N = len(S)
    ans = 10**7
    for k in range(N-1):
        if S[k] != S[k+1]:
            ans = min(ans, max(k + 1, N - k - 1))
    print(ans if ans < 10**6 else N)


if __name__ == '__main__':
    main()

Solution (Python):
S = input()
N = len(S)
M = N//2
if N%2:
    for i in range(M):
        if S[M+i] != S[M+i+1]:
            print(M+i+1)
            exit()
        if S[M-i] != S[M-i-1]:
            print(M+i+1)
            exit()
    print(N)
else:
    if S[M] != S[M-1]:
        print(M)
        exit()
    for i in range(M-1):
        if S[M+i] != S[M+i+1]:
            print(M+i+1)
            exit()
        if S[M-i-1] != S[M-i-2]:
            print(M+i+1)
            exit()
    print(N)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

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


def main():
    S=ST()
    ans = len(S)
    for i in range(1,len(S)):
        if S[i-1]!=S[i]:
            ans = min(ans, max(i, len(S)-i))
    print(ans)
        
    
    
    

if __name__ == '__main__':
    main()

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

Solution (Python):
S = list(map(int,list(input())))
N = len(S)
cmax = 0
for i in range(1,N):
    if S[i]!=S[cmax]:
        if cmax<=N-i:
            cmax = i
        else:
            cmax = max(cmax,N-cmax)
            break
cmax = max(cmax,N-cmax)
print(cmax)

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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)

K = N
for i in range(N-1):
    
    
    if S[i] != S[i+1]:
        tmp = max(i+1, N - (i+1))
        K = min(K, tmp)

print(K)

Solution (Python):
import sys


stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

S = list(input())
N = len(S)
answer = (N+1)//2

if len(set(S)) == 1:
    print(N)
    exit()
right = N
left = answer

while right > left + 1:
    mid = (right + left) // 2
    S2 = S[-mid:mid]
    if len(set(S2)) == 1:
        left = mid
    else:
        right = mid

print(left)

Solution (Python):
s = input()
boundary = []
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 sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

S = [int(x) - ord('0') for x in read().rstrip()]

N = len(S)

Scum = list(itertools.accumulate(S))

def test(x):
    if x + x <= N:
        return True
    L = N - x
    R = x
    cnt = Scum[R-1] - Scum[L] + S[L]
    return cnt in [0,R-L]

left = 0 
right = N + 1 
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        left = x
    else:
        right = x
answer = left
print(answer)

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

Solution (Python):
S = input()

S = S + '2'
D = []
p = S[0]
l = 0
for i in range(len(S)):
  if S[i] == p:
    l += 1
  else:
    D.append((p,l))
    l = 1
    p = S[i]


if len(D) == 1:
  print(len(S)-1)
else:
  csum =[D[0][1]]
  for i in range(1,len(D)):
    csum.append(csum[-1]+D[i][1])
  ans = float('inf')
  for i in range(len(D)-1):
    ans = min(max(csum[i],csum[len(D)-1]-csum[i]),ans)
  print(ans)

Solution (Python):
from bisect import bisect_right
s = input()
n = len(s)
l = [0, 1]
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        l[-1] += 1
    else:
        l.append(l[-1]+1)
i = bisect_right(l, n // 2)
print(min(n - l[i - 1], l[i]))

Solution (Python):

S = input()

z = 0
o = 0

for i in S:
    if i == "0":
        z += 1
    else:
        o += 1

for i in range(len(S)):

    if o == 0 or z == 0:
        print (len(S) - i)
        break

    if S[i] == "0":
        z -= 1
    else:
        o -= 1

    if S[-1-i] == "0":
        z -= 1
    else:
        o -= 1

Solution (Python):
def read_values():
    return map(int, input().split())


def read_list():
    return list(map(int, input().split()))


def main():
    S = input()
    N = len(S)

    i = 1
    prev = S[0]
    res = N
    for s in S[1:]:
        if prev != s:
            res = min(res, max(i, N - i))
        prev = s
        i += 1
    
    print(res)
    

if __name__ == "__main__":
    main()

Solution (Python):
S = input()

ans = N = len(S)
for i, (s, t) in enumerate(zip(S, S[1:]), 1):
    if s != t:
        ans = min(ans, max(i, N - i))

print(ans)

Solution (Python):
s = tuple(map(int, input()))
n = len(s)

ret = n
p = s[0]
for i, x in enumerate(s):
    if x != p:
        ret = min(ret, max(i, n - i))
    p = x
print(ret)

Solution (Python):
def is_ok(k):
    imos = [0] * (len(s) + 2)

    for i, x in enumerate(s, 1):
        imos[i] ^= imos[i - 1]
        if i <= len(s) - (k - 1):
            
            if x ^ imos[i - 1]:
                imos[i] ^= 1
                imos[i + k] ^= 1
        else:
            if x ^ imos[i - 1]:
                return i > k
    return True


def binary_search():
    ok = 1
    ng = len(s) + 1
    while abs(ng - ok) > 1:
        mid = (ng + ok) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


s = tuple(map(int, input()))
print(binary_search())

Solution (Python):

S = list(str(input()))

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

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

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

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

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



S = str(input())

n = len(S)

ans = n
for i in range(1,n):
    if S[i]!=S[i-1]:
        temp = max(i,n-i)
        if temp<ans:
            ans = temp

print(ans)

Solution (Python):
S=input()
c=''
p=[0]
for s in S:
    if c!=s:
        p.append(p[-1]+1)
        c=s
    else:
        p[-1]+=1
print(min([max(p[i],len(S)-p[i]) for i in range(1,len(p))]))

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

if N%2 == 1:
    ans = N//2
    s = S[N//2]
    a = N//2+1
    for i in range(N//2+1):
        if S[N//2+i] != s or S[N//2-i] != s:
            a = i
            break
    ans += a
else:
    ans = N//2
    s = S[N//2]
    a = N//2
    for i in range(N//2):
        if s != S[N//2-1-i] or s != S[N//2+i]:
            a = i
            break
    ans += a
print(ans)

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

S = input()

length_list = []
length = 1
now = S[0]
for i in range(1, len(S)):
	if now != S[i]:
		length_list.append(length)
		now = S[i]
		length = 1
	else:
		length += 1
length_list.append(length)

sum_list = []
x = 0
for i in range(len(length_list)):
	x += length_list[i]
	sum_list.append(x)

ans = 10000000000000
for i in range(len(length_list)):
	ans = min(ans, max(len(S) - sum_list[i], sum_list[i]))

print(ans)

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

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

change = []
for i in range(1, N):
    if S[i - 1] != S[i]:
        change.append(min(i, N - i))
if change:
    print(N - max(change))
else:
    print(N)

Solution (Python):
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def solve():
  s = input()
  n = len(s)
  query = [0]*n
  for i in range(n-1):
    if s[i] != s[i+1]:
      query[i] = max(i+1,n-i-1)
  
  if (s == "0"*n) or (s=="1"*n):
    print(n)
  else:
    ans = 10**12
    for i in query:
      if i!= 0:
        ans = min(ans,i)
    print(ans)
solve()

Solution (Python):
S = input()

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

print(ans)

Solution (Python):
S = input()


N = len(S)
M = N // 2
ans = M + next(
    (
        i
        for i in range(N - M)
        if (
            S[M - i - 1] != S[M] or S[M + i] != S[M] if N % 2 == 0 else
            S[M - i] != S[M] or S[M + i] != S[M]
        )
    ),
    N - M
)

print(ans)

Solution (Python):
from itertools import takewhile

S = input()



N = len(S)
M = N // 2
ans = M + len(
    list(
        takewhile(
            lambda i:
                S[M] == S[M - i - 1] == S[M + i] if N % 2 == 0 else
                S[M] == S[M - i] == S[M + i],
            range(N - M)
        )
    )
)

print(ans)

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

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

S = input()


if len(S) % 2 == 1:
    ans = len(S) // 2 + 1
    L = len(S) // 2
    r = len(S) // 2
else:
    ans = len(S) // 2
    L = len(S) // 2
    r = len(S) // 2 - 1


color = S[L]
while L - 1 >= 0 and S[L - 1] == S[r + 1] == color:
    L -= 1
    r += 1
    ans += 1
print(ans)

Solution (Python):
def main():
    s = input()
    i = j = len(s) // 2
    if len(s) % 2 == 0:
        j -= 1
    ss = s[j]
    while len(s) > i and j >= 0 and ss == s[i] and ss == s[j]:
        i += 1
        j -= 1
    print(i)


main()

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

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