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() + '

pressed = []

prev = S[0]
count = 0
for s in S:
    if s == prev:
        count += 1
    else:
        prev = s
        pressed.append(count)
        count = 1

left_cumsum = []
right_cumsum = []

cumsum = 0
for count in pressed:
    cumsum += count
    left_cumsum.append(cumsum)

cumsum = 0
for count in pressed[::-1]:
    cumsum += count
    right_cumsum.append(cumsum)

length = len(left_cumsum)

if length == 1:
    print(len(S)-1)
    exit()

change_k = [0] * length

for idx in range(1, length):
    k = right_cumsum[-idx-1]
    change_k[idx-1] = k

for idx in range(1, length):
    k = left_cumsum[-idx-1]
    change_k[-idx] = max(change_k[-idx], k)

ans1 = min(change_k[::2])
ans2 = min(change_k[1::2])
print(max(ans1, ans2))

Solution (Python):


S = input()

N = len(S)
ans = N

if N == 1:
    print(1)
else:
    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)
k = 10**9
if not "1" in s:
    print(n)
elif not "0" in s:
    print(n)
else:
    for i in range(n-1):
        if s[i] != s[i+1]:
            k = min(k,max(i+1,n-(i+1)))
    if k > n:
        print(n)
    else:
        print(k)

Solution (Python):
from itertools import groupby
S = input()
N = len(S)
G = [len(list(l)) for _, l in groupby(S)]
A = 0
for g in G:
    A += g
    if A >= (N+1) // 2:
        ans = min(A, N-A+g)
        print(ans)
        break

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

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

K = (N+1)//2
X = set()
if N&1:
  X = {S[K-1]}
  l = K-2
  r = K
else:
  X = set()
  l = K-1
  r = K
  
while l:
  X.add(S[l])
  X.add(S[r])
  if len(X)>1: break
  K += 1
  l -= 1
  r += 1

print(K)

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)
ans=n
for i in range(n-1):
    if s[i]!=s[i+1]:
        t=max(i+1,n-i-1)
        ans=min(ans,t)

print(ans)

Solution (Python):
"""import sys
input = sys.stdin.readline"""
S=input()
t=10**6
for i in range(1,len(S)):
    if S[i-1]!=S[i]:
        t=min(t,max(i,len(S)-i))

if t==10**6:
    print(len(S))
else:
    print(t)

Solution (Python):
s = input()
n = len(s)
ans = (n+1)//2
if n%2:
    x = s[n//2]
    for i in range(1,n//2+1):
        if s[n//2-i] == s[n//2+i] == x:
            ans += 1
        else:
            break
if n%2==0:
    if s[n//2] == s[n//2-1]:
        ans += 1
        x = s[n//2]
        for i in range(1,n//2):
            if s[n//2-1-i] == s[n//2+i] == x:
                ans += 1
            else:
                break
print(ans)

Solution (Python):
from itertools import groupby, accumulate

S = list(input())
n = len(S)
s = list(accumulate([len(list(j)) for i, j in groupby(S)]))
s = [max(i, n - i) for i in s]

print(min(s))

Solution (Python):

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)



show_flg = True


def main():
    S = input()
    center = len(S) // 2

    if len(S) % 2 == 0:
        c = 1
        while True:
            if (center - 1 + c) < len(S) and S[center - c] == S[center - 1 + c] and S[center - c] == S[center]:
                
                
                c += 1
            else:
                
                
                break
        print(c + center - 1)
    else:
        c = 0
        while True:
            if (center + c) < len(S) and S[center - c] == S[center + c] and S[center] == S[center - c]:
                c += 1
            else:
                break
        print(c + center)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

s = sys.stdin.readline().rstrip()
n = len(s)

def main():
    m = n // 2
    if n & 1:
        l = s[m::-1]
        r = s[m:]
    else:
        l = s[m-1::-1]
        r = s[m:]
    base = l[0]

    cnt = m
    i = 0
    if n & 1:
        m += 1
    while i < m:
        if l[i] == r[i] == base:
            i += 1
            cnt += 1
        else:
            break
    return cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
s = input()
lns = len(s)
r = lns
for i, (b, c) in enumerate(zip(s, s[1:])):
    if b != c:
        r = min(r, max(i+1, lns-i-1))
print(r)

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):
import numpy as np
S=str(input())
X=[]
c=1
for i in range(1,len(S)):
  if S[i]==S[i-1]:
    c +=1
  elif S[i]!=S[i-1]:
    X +=[c]
    c=1
  if i==len(S)-1:
    X +=[c]
if len(S)==1:
  X=[1]
if len(X)>=3:
  X=np.cumsum(X)
  t=float('inf')
  for i in range(len(X)-1):
    u=max(X[i],len(S)-X[i])
    t=min(u,t)
  answer=t
elif len(X)==1:
  answer=X[0]
elif len(X)==2:
  answer=max(X)
print(answer)

Solution (Python):
s=input()
n=len(s)
if n % 2 == 1:
    hn = n//2
    if s[hn] =="1":
        s=s.replace("1","p").replace("0","1").replace("p","0")
    res = 0
    while res <= hn and s[hn+res] == "0" and s[hn-res] == "0":
        res += 1
    print(res+hn if res != 0 else hn+1)
else:
    hn = n//2
    res = 0
    if s[hn] =="1" and s[hn-1]=="1":
        s=s.replace("1","p").replace("0","1").replace("p","0")
    while res < hn and s[hn+res] == "0" and s[hn-res-1] == "0":
        res += 1
    print(res+hn)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import bisect
from logging import getLogger, StreamHandler, DEBUG, WARNING
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)


logger.addHandler(handler)
def main():
    s = input().strip()
    n = len(s)
    tmp = s[0]
    ans = 0
    for i , c in enumerate(s):
        if tmp != c:
            if i > ans:
                ans = i

        if i >= (n) // 2:
            break
        tmp = c


    tmp = s[-1]
    for i, c in enumerate(s[::-1]):
        if tmp != c:
            if i > ans:
                ans = i

        if i >= (n) // 2:
            break
        tmp = c

    print(n - ans)

    

if __name__ == "__main__":
    main()

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    S=input()
    n=len(S)

    def check(k):
        if(n-k>=k): return True
        else: return len(set(S[n-k:k]))==1

    print(bisection(1,n,check))
resolve()

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

K = N // 2

if N % 2 == 0:
    if S[K - 1] == S[K]:
        tmp = S[K - 1]
    else:
        print (K)
        exit()
    i = 0
    while i < K and S[K - 1 - i] == S[K + i] == tmp:
        i += 1
    print (K + i)
else:
    tmp = S[K]
    i = 1
    while i <= K and S[K - i] == S[K + i] == tmp:
        i += 1
    print (K + i)

Solution (Python):
import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

S = str(input())
N = len(S)
ans = int(0)

k = N

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

Solution (Python):
s = input()
i = (len(s) - 1) // 2
j = len(s) // 2
k = s[i]
while i >= 0:
  if s[i] != k or s[j] != k:
    break
  i -= 1
  j += 1
if i <  0:
  print(len(s))
else:
  print(j)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = list(input())
N = len(S)

ans = ceil(N, 2)
for i in range(ceil(N, 2), N):
    
    if not S[i] == S[N-1-i] == S[i-1]:
        break
    ans += 1
print(ans)

Solution (Python):
s=input()
n=len(s)
if n%2==0:
    a=n//2-1
    b=n//2
    l=0
    r=0
    for i in range(1,n//2+1):
        if s[b-i]==s[b-i+1]:
            l+=1
            continue
        else:
            break
    for i in range(1,n//2+1):
        if s[a+i]==s[a+i-1]:
            r+=1
            continue
        else:
            break
    ans=n//2+min(l,r)
    print(ans)
else:
    a=n//2
    l=1
    r=1
    for i in range(1,n//2+1):
        if s[a-i]==s[a-i+1]:
            l+=1
            continue
        else:
            break
    for i in range(1,n//2+1):
        if s[a+i]==s[a+i-1]:
            r+=1
            continue
        else:
            break
    ans=n//2+min(l,r)
    print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

s = S()
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)
L = []
temp = S[0]
c = 1
for i in range(1, N-1):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
if S[N-1] == temp:
    c += 1
else:
    L.append(c)
    c = 1
L.append(c)

ans = N
while len(L) >= 3:
    if L[0] > L[-1]:
        ans = min(ans, N-L[-1])
        L[-2] += L[-1]
        L.pop(-1)
    else:
        ans = min(ans, N-L[0])
        L[1] += L[0]
        L.pop(0)
        
if len(L) == 2:
    ans = min(ans, max(L))
    
print(ans)

Solution (Python):

S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2
l = r = center_i
if N%2==0:
    l -= 1
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)

Solution (Python):



import numpy as np
arr = np.array([int(x) for x in input()])
arr_c = arr.cumsum()

N = arr.size

answer = 0

for K in range(N,0,-1):
  left = N-K
  right = K-1
  
  if left >= right:
    answer = K
    break
  one_cnt = arr_c[right] - arr_c[left] + arr[left]
  zero_cnt = (right - left + 1) - one_cnt
  if one_cnt == 0 or zero_cnt == 0:
    answer = K
    break
    
print(answer)

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

print(ans)

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

l, r, p = 0, 0, s[L // 2]
if L % 2 == 0:
    l, r = L // 2 - 1, L // 2
else:
    l, r = L // 2, L // 2

cnt = 0
while l >= 0 and r < L and s[l] == s[r] == p:
    p = s[l]
    cnt += 1
    l -= 1
    r += 1

print(cnt + L // 2)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Solution (Python):
S = input()
N = len(S)
l = 0
a = {}
if N%2==0:
    if S[N//2] != S[N//2-1]:
        print(N//2)
    else:
        flag = S[N//2]
        l = 2
        i = 1
        while i <= N//2-1:
            if S[N//2+i]==flag and S[N//2-1-i]==flag:
                l+=2
                i += 1
            else:
                break
        print(N//2+l//2)
else:
    flag = S[N//2]
    i = 1
    l = 1
    while i <= N//2:
        if S[N//2+i]==flag and S[N//2-i]==flag:
            l += 2
            i += 1
        else:
            break
    print((N-l)//2 + l)

Solution (Python):
import itertools
S = list(itertools.accumulate([0] + [int(_) for _ in input()]))
N = len(S) - 1
for i in range(N, 0, -1):
    if 2 * i < N:
        break
    if S[i] - S[N - i] in [0, 2 * i - N]:
        break
print(i)

Solution (Python):
s = input() + '.'

count = []
pre = s[0]
c = 1
for t in s[1:] :
    if t == pre :
        c += 1
    else :
        count.append(c)
        pre = t
        c = 1
        
m = float('inf')
tot = sum(count)
now = 0
for c in count :
    now += c
    m = min(m, max(now, tot-now))
print(m)

Solution (Python):
s = input()
n = len(s)
t = s[::-1]
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)
if n%2==0:
    if s[n//2-1]!=s[n//2]:
        print(n//2)
    else:
        for i in range(2,n//2+1):
            if s[n//2-i]!=s[n//2] or s[n//2-1+i]!=s[n//2]:
                print(n//2+i-1)
                break
        else:
            print(n)
else:
    for i in range(1,n//2+1):
        if s[n//2-i]!=s[n//2] or s[n//2+i]!=s[n//2]:
            print(n//2+i)
            break
    else:
        print(n)

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, c, d = LI()
    a += b
    c += d
    ans = ["Left", "Right"]
    if a == c:
        print("Balanced")
        return
    print(ans[a < c])
    return


def B():
    n, a, b = LI()
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans) 
    
    return


def C():
    x, y = LI()
    ans = 0
    while x <= y:
        ans += 1
        x *= 2
    print(ans)
    return





def D():
    s = S()
    ans = inf
    n = len(s)
    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 != inf else n )
    return


if __name__ == '__main__':
    D()

Solution (Python):
S = input()


boundary = []
pre_state = '0'
for i in range(len(S)):
  if S[i] != pre_state:
    boundary.append(i)
    pre_state = S[i]
else:
  if S[-1] == '1':
    boundary.append(len(S))
    
if len(boundary) == 0:
  print(len(S))
  exit()
    

lst = []
for i in range(len(boundary)):
  lst.append(max(boundary[i], len(S)-boundary[i]))
ans = min(lst)
print(ans)

Solution (Python):
S = input()
c0 = S[len(S)//2]
r = S.find("1" if c0 == "0" else "0", len(S)//2)
if r < 0: r = len(S)
l = S.rfind("1" if c0 == "0" else "0", 0, len(S)//2)
l += 1
K = min(r, len(S)-l)

print(K)

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

Solution (Python):
s = input()
"""
s = '101'
s = '100000000'
s = '00001011'
"""
k = len(s)
for i in range(1, len(s)):
    if s[i-1] != s[i]:
        k = min(k, max(i, len(s)-i))
print(k)

Solution (Python):
S = input()
b = []
for i in range(len(S) - 1):
    if S[i:i + 2] == "01" or S[i:i + 2] == "10":
        b.append(len(S) - (i + 1) if i < len(S) // 2 else i + 1)

print(min(b) if len(b) != 0 else len(S))

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

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)

def f(k):
    s = S[-k:k]
    if s == "":return False
    return s.count(s[0])!=len(s)

def binary_search(l,r,func):
    if func(l):return l-1
    if not func(r):return r
    while l+1<r:
        i = (l+r)//2
        if func(i):
            r = i
        else:
            l = i
    return l

print(binary_search(0,N,f))

Solution (Python):
w=input()
a=[(i+1)*(j=="0") for i,j in enumerate(w)]
b=[(i+1)*(j=="1") for i,j in enumerate(w)]
l=len(w)
ma=a[0];mb=b[0]
for t in range(1,l+1):
	ma=max(ma,a[t-1])
	mb=max(mb,b[t-1])
	m=min(ma,mb)
	if l-m<t:
		print(t-1)
		exit()
print(l)

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

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

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

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

Solution (Python):
S = input()

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

Solution (Python):
S = input()

l = (len(S)-1)//2
r = len(S)//2
m = S[l]
while l >= 0:
    if S[l] != m or S[r] != m:
        break
    l -= 1
    r += 1
if l < 0:
    print(len(S))
else:
    print(r)

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

Solution (Python):
S = input()
length = len(S)
temp = []
for i in range(1,length):
    if S[i] != S[i-1]:
        temp.append(max(i , length - i))
if len(temp) == 0:
    print(length)
else:
    print(min(temp))

Solution (Python):
S = input()

ans = len(S)// 2
if len(S) % 2 == 1:
    ans += 1

t = S[len(S)//2]
c = ans
for i in range(len(S)//2-1,-1,-1):
    if S[i] == S[c] and S[i] == t:
        ans += 1
        c += 1
    else:
        break
print(ans)

Solution (Python):
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2+1
    c = ans
    t = S[ans-1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break


print(ans)

Solution (Python):
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2+1
    c = ans
    t = S[ans-1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break

    ans = max(len(S)//2,ans)

print(ans)

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

Solution (Python):
s = raw_input()
length = len(s)
if length == 1:
    print 1
    exit()
T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
if len(T) == 0:
    print length
else:
    print min(T)

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

Solution (Python):
s=input()
n=len(s)
if n%2==0:
    ans=n//2
    if s[n//2-1]==s[n//2]:
        ans=ans+1
        a=s[n//2]
        x=n//2-1
        y=n//2
        while True:
            if x==0:
                break
            x,y=x-1,y+1
            if s[x]==a and s[y]==a:
                ans=ans+1
            else:
                break
else:
    a=s[(n-1)//2]
    ans=(n-1)//2+1
    x=(n-1)//2
    y=(n-1)//2
    while True:
        if x==0:
            break
        x,y=x-1,y+1
        if s[x]==a and s[y]==a:
            ans=ans+1
        else:
            break
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

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

Solution (Python):


s=input()
a=s[(len(s)-1)//2::-1]
b=s[len(s)//2:]
if a[0]!=b[0]:
    print(len(s)//2)
else:
    c=str(1-int(a[0]))
    m = (a+c).find(c)
    n = (b+c).find(c)
    print(len(s)//2+min(m,n))

Solution (Python):
S = input()
if S.count('1') == 0 or S.count('0') == 0:
    print(len(S))
    exit()

c = S[0]
len_s = len(S)
mx = len_s
for s in range(1,len_s):
    if c != S[s]:
        mx = min(mx, max(len_s -s, s))
    c = S[s]
print(mx)

Solution (Python):
S = str(input())
L = len(S)
valueChangedIndex = []
s = S[0]
for i in range(1, L):
    if S[i] != s:
        valueChangedIndex.append(max(i, L-i))
    s = S[i]

if len(valueChangedIndex) == 0:
    print(L)
else:
    print(min(valueChangedIndex))

Solution (Python):
S = input()

mi = len(S) // 2 + len(S) % 2 

if len(S) % 2 == 0:
  l = mi - 1
  r = mi
  if S[l] != S[r]:
    print(r)
    exit()
else:
  l = mi - 1
  r = mi - 1

re = S[l]
for i in range(l):
  if S[l - 1 - i] != re or S[r + 1 + i] != re:
    ans = r + i + 1
    break
else:
  ans = len(S)


print(ans)

Solution (Python):
S=input()
if len(S)==1:
    print(1)
    quit()
if len(S)%2==0:
    A=S[:len(S)//2]
    B=S[len(S)//2:]
    A=A[::-1]
    s=A[0]
    ans=len(S)//2
if len(S)%2==1:
    A=S[:len(S)//2]
    B=S[len(S)//2+1:]
    A=A[::-1]
    s=S[len(S)//2]
    ans=len(S)//2+1
for i in range(len(A)):
    if A[i]!=s or B[i]!=s:
        print(ans+i)
        quit()
print(len(S))

Solution (Python):
import math

def main():
    data = list(input())
    pre = data[0]
    ans = len(data)
    for i in range(1, len(data)):
        if pre != data[i]:
            ans = min(ans, max(i, len(data) - i))
            pre = data[i]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import*;s=input();print(min(max(len(s)-i,i)for i in accumulate(len(list(v))for k,v in groupby(s))))

Solution (Python):


from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul
from bisect import* 
from heapq import* 
from math import factorial
from copy import deepcopy
import sys

sys.setrecursionlimit(10**6)


def main():
    bound=0
    ans=[]
    s=input()
    for k,v in groupby(s):
        bound+=len(list(v))

        ans.append(max(bound,len(s)-bound))
    print(min(ans))
    
    
if __name__ == '__main__':
    main()

Solution (Python):











import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
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 [input() 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 main():
    S = ST()
    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)
if __name__ == '__main__':
    main()

Solution (Python):
s = input()



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

if len(tmp) == 0:
        
        print(len(s))
else:
        print(min(tmp))

Solution (Python):

import sys
INF = float("inf")


def solve(S: str):

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


def main():

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


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
n=len(s)
ss=s[0]
C=[]
for i in range(1,n):
  if s[i]!=ss:
    C.append(max(i,n-i))
  ss=s[i]
print(n if len(C)==0 else min(C))

Solution (Python):
S = input()

e = '0'
s = 0
li = []
for v in S:
  if v == e:
    s += 1
  else:
    li.append(s)
    s = 1
    e = v
if ( s > 0):
  li.append(s)

lis = [0]*( len(li) + 1 )
for i in range(len(li)):
  lis[i+1] = lis[i] + li[i]

gg = lis[-1]
sm = 100000000000000000000
for v in lis:
  sm = min(sm,max(v,gg-v))
print ( sm )

Solution (Python):
s = input()
n = len(s)
if n%2 == 0:
  a = n//2 - 1
  b = n//2
  c = 2
  d = s[a]
  if s[b] != d:
    print(n//2)
    quit()
else:
  a = n//2
  b = n//2
  c = 1
  d = s[a]
while a-1 >= 0 and s[a-1] == d and s[b+1] == d:
  a -= 1
  b += 1
  c += 2
print(n-(n-c)//2)

Solution (Python):


s = input()

size = len(s)
ans = size

for i in range(size-1):

    if s[i] != s[i+1]:

        t = max(i+1,size-i-1)

        ans = min(ans,t)

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()

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)

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

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

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

la=[0]
lb=[0]

for i in s:
    if i=="0":
        la.append(la[-1]+1)
        lb.append(lb[-1])
    else:
        lb.append(lb[-1]+1)
        la.append(la[-1])

if n%2==0:
    for i in range(n//2+1):
        if la[n//2+i]-la[n//2-i]==0 or lb[n//2+i]-lb[n//2-i]==0:
            ans=n//2+i
else:
    for i in range(n//2+1):
        if la[n//2+i+1]-la[n//2-i]==0 or lb[n//2+i+1]-lb[n//2-i]==0:
            ans=n//2+i+1

print(ans)

Solution (Python):
S = input()
n = len(S)
ans = len(S)
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):
import math

S = input()
N = len(S)

cntl = []
tmp = S[0]
cnt = 1
for i in range(1,N):
  if tmp == S[i]:
    cnt += 1
  else:
    cntl.append(cnt)
    cnt = 1
    tmp = S[i]
else:
  cntl.append(cnt)

SUM = cntl[0]
ans = max(N-cntl[0],N-cntl[-1])
for i in range(1,len(cntl)-1):
  ans = min(ans,min(N-SUM,SUM+cntl[i]))
  SUM += cntl[i]
"""
if ans == 0:
  print(N)
else:
  print(ans)
"""
SSUM = 0
for i in cntl:
  SSUM += i
  if SSUM >= math.ceil(N/2):
    print(min(SSUM,N-(SSUM-i)))
    break

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

prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    
if cand:
    print(min(cand))
else:
    print(n)