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



Sample input:
010


Sample output:
2

Submission status: Accepted

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

# from itertools import product, permutations, combinations, combinations_with_replacement
# from itertools import accumulate
# from operator import itemgetter
# from bisect import bisect_bound_list,bisect
# from heapq import heappop,heappush
# from math import ceil,floor
# from copy import deepcopy
# from heapq import heappop,heappush,heapify
# import heapq


# def combinations(n, r):
# 	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# def gcd(a, b):
# 	if b == 0:
# 		return a
# 	else:
# 		return gcd(b, a%b)
 
# def lcm(a, b):
# 	return a // gcd(a, b) * b

# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

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 LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# https://emtubasa.hateblo.jp/entry/2019/02/14/000000_2

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

# 異なる文字の境界で
# 左端、右端からその境界までの距離のうち長い方を反転させることで、
# その境界をなくすことができる
# そのような長い方の距離の最小値であれば、どの境界であっても処理できる

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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  # @lru_cache(None)
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)

Submission status: Accepted

Solution code:
# ARC088D
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)
#print(r)

# k未満を使わずに反転可能な最大のKは？
ok = 0
ng = N + 1

while ok + 1 < ng:
    med = (ng + ok) // 2
    # medで一発が必要なのは？
    le = N - med
    ri = med
    #print(le,ri)
    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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#解説参照
#隣接が異なる箇所を操作する必要がある
#max(i,n-i)の最小値がkの下限
#逆に上限であることは、異なる箇所から(右か左の)端までを反転させれば隣接が異なる箇所が減る

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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:



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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#from collections import *
from itertools import *
#from bisect import *
#from heapq import *
#import copy
#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]
#import math
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)

Submission status: Accepted

Solution code:
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 # and False
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def main():
    # 解説AC
    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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# ??
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)

Submission status: Accepted

Solution code:

S = input()

N = len(S)
# 文字列がすべて同じ文字ならK=Nになるので
K = N
for i in range(N-1):
    # iとその右の文字が異なる場合、長い方を書き換えるとKをなるべく大きく保てる
    # Kの減る幅をなるべく小さように選んでいくイメージ。
    if S[i] != S[i+1]:
        tmp = max(i+1, N - (i+1))
        K = min(K, tmp)

print(K)

Submission status: Accepted

Solution code:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 # True
right = N + 1 # False
while left + 1 < right:
    x = (left + right) // 2
    if test(x):
        left = x
    else:
        right = x
answer = left
print(answer)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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]
#print(D)

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)

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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):
            # 連続kの区間をi起点に取ることができる
            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())

# Kで達成できるとき、K未満で達成できる
# TTTTFFF
#    ^
#    K
# 二分探索する

Submission status: Accepted

Solution code:
#D
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
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)
  #print(query)
  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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S = input()
t = len(S)
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        need = max(i+1,len(S)-i-1)
        t = min(need,t)
print(t)

Submission status: Accepted

Solution code:
s = input()

ans = len(s)
m = 1
for i in range(len(s)):
    if s[i]== str(m):
        if i<(len(s)+1)//2:
            ans = len(s)-i
            m = (m+1)%2
        else:
            ans = min(ans,i)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)

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


solve()

Submission status: Accepted

Solution code:
# [a,b] - [a,b) = {b} なので、端の方は自由。
# 中央が単色であるかを確認すればよい。

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
  # [left,right]が単色であればよい
  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)

Submission status: Accepted

Solution code:
S=input()

from itertools import groupby, accumulate

_l = [len(list(g)) for k,g in groupby(S)]
_l_cs = [0] + list(accumulate(_l))
_l_cs_r = list(accumulate(_l[::-1]))[::-1] + [0]

answer = len(S)
for i, r in zip(_l_cs, _l_cs_r):
  answer = min(answer, max(i,r))

print(answer)

Submission status: Accepted

Solution code:
s = input()
k = len(s)
for i in range(1, len(s)):
    if s[i] != s[i - 1]:
        m = max(i, len(s) - i)
        if m < k:
            k = m
print(k)

Submission status: Accepted

Solution code:
S=input()

b = S[0]
n=len(S)
res=10**9
if("1" not in S):
    print(n)
    exit()
if("0" not in S):
    print(n)
    exit()
for i in range(1,n):
    if S[i]!=b:
        res=min(res,max(i,n-(i)))
    b=S[i]

print(res)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys
import math


s = str(input())
n = len(s)
sn = []
cont = 1
for i in range(1,n):
  if s[i-1] != s[i]:
    sn.append(cont)
    cont = 1
  else:
    cont += 1
sn.append(cont)

# ->
sm_l = 0
for i in sn:
  if sm_l < (n+1)//2:
    sm_l += i

# <-
sn = reversed(sn)
sm_r = 0
for i in sn:
  if sm_r < (n+1)//2:
    sm_r += i

print(min(sm_l,sm_r))

Submission status: Accepted

Solution code:
S = input()
ans = float('inf')
for i in range(len(S)-1):
  if S[i] != S[i+1]:
    k = max(i+1,len(S)-i-1)
    if k <= ans:
      ans = k
if ans != float('inf'):
  print(ans)
else:
  print(len(S))

Submission status: Accepted

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

left = 0
right = n-1
ans = [-1 for i in range(n)]

def judge(m):
    if n>=2*m:
        return 1

    for i in range(n-m,m-1):
        if s[i] != s[i+1]:
            return 0
    return 1

while left <= right:
    mid = (left+right)//2
    #print(mid)

    if judge(mid+1):
        ans[mid]  = 1
        left = mid+1

    else:
        ans[mid]  = 0
        right = mid-1
#print(ans)

for i in range(n):
    if ans[-i-1] ==1:
        print(n-i)
        break

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans = n

num = S[0]
for i in range(n):
    if num != S[i]:
        ans = min(ans,max(i,n-i))
        num = S[i]
print(ans)