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:
S = input()

len_S = len(S)
if len_S % 2 == 0:
    half_len = int(len_S / 2)
else:
    half_len = int(len_S / 2) + 1

idx = None
target = None

for i in range(half_len):
    if S[i] == S[-i-1]:
        if target == None:
            target = S[i]
            idx = i
        else:
            if S[i] != target:
                target = S[i]
                idx = i
            else:
                continue
    else:
        target = None
        idx = None

if idx != None:
    print(len_S - idx)
else:
    print(half_len)

Submission status: Accepted

Solution code:
import sys

change = False
debug = False


def print_err(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def main():
    """
    0 と 1 からなる文字列 S が与えられます。
    以下の操作を好きな回数繰り返すことで S の要素をすべて 0 にできるような、|S| 以下の最大の整数 K を求めてください。
    S の長さ K 以上の連続する区間 [l,r] を選ぶ(すなわち、r−l+1≥K が満たされる必要がある)。
    l≤i≤r なるすべての整数 i に対し、Si が 0 なら Si を 1 に、Si が 1 なら Si を 0 に置き換える。
    制約
    1≤|S|≤105
    Si(1≤i≤N) は 0 または 1 である
    """
    S = input()

    f(S)


def f(S):
    """
    最大となるKより、1つずつ変えるのは最後の手段
    ※K以上の反転可能であるため

    000: OK
    001, 110:  -> 100, 011
    010, 101:
      11を最終的に反転するように修正していく
        101: 1-3 all
        011: 1-2
        000: 2-3
    011, 100: 11を反転でOK

    0001 となっているとき
    K=3とすれば
    000 をまず反転、その後K+1まで反転すれば、初期状態からK+1番目のみ反転できる
    """
    n = len(S)
    ans = n

    # 反転確認
    table = str.maketrans('01', '10')
    for k in range(1, n):
        if S[k] == S[k - 1]:
            continue

        t = max(k, n - k)
        ans = min(ans, t)

        # 反転を利用して異なる部分を変更
        # 要素数の多い方を対称の異なる文字含めて反転

        # CPython3, PyPy: TLE
        if change:
            if t == k:
                S = S[:t].translate(table) + S[t:]
            else:
                S = S[:k] + S[k:].translate(table)

            if debug:
                print_err("t:", t, "k:", k, "S:", S, sep="\t")

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = list(raw_input())

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
else:
    mx = max(mx, min(i+1, len(l)-x))
print mx

Submission status: Accepted

Solution code:
import re

n=input()
min=10000000
N=len(n)
for i in range(N-1):
    if n[i]!=n[i+1]:
        if max(i+1,N-i-1) < min:
            min=max(i+1,N-i-1)
if min==10000000:
    min=N

print(min)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
S = input()
n = len(S)
ans = n // 2
pv = S[n // 2]
for i in range(n // 2, n):
    new = [S[n - i - 1], S[i]]
    if set(new) != set(pv):
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
S = input()
n = len(S)
ans = n // 2
for i in range(n // 2, n):
    if S[n - i - 1] != S[n // 2] or S[i] != S[n // 2]:
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
S = input().strip()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
s = input()
count = 1
slist = list(s)
strlen = len(s)
count = None
if strlen % 2 == 1:
    count = math.ceil(strlen/2)
    center = slist[math.floor(strlen/2)]
    for i in range(math.floor(strlen/2)):
        if center == slist[math.floor(strlen/2)- i - 1] and center == slist[math.ceil(strlen/2)+i]:
            count +=1
        else:
            break
else:
    count = strlen / 2
    center = slist[int(strlen/2)]
    for i in range(int(strlen/2)):
        if center == slist[int(strlen/2)+i] and center == slist[int(strlen/2) - 1 - i]:
            count += 1
        else:
            break
print(int(count))

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

zero = "00"

one = "11"

if len(S) % 2 == 0:
	
	Ans = int(len(S) / 2 )
	flont = Ans - 1
	back = Ans + 1
	while (1):
		if S[flont:back] == zero:
			zero += "00"
			flont -= 1
			back += 1
			Ans += 1
			continue
		if S[flont:back] == one:
			one += "11"
			flont -= 1
			back += 1
			Ans += 1
			continue
		else:
			break

if len(S) % 2 == 1:
	zero = "0"
	one = "1"
	Ans = int(len(S) / 2 + 0.5)
	flont = Ans - 1
	back = Ans
	while(1):
		if S[flont:back] == zero:
			zero += "00"
			flont -= 1
			back += 1
			Ans += 1
			continue
		if S[flont:back] == one:
			one += "11"
			flont -= 1
			back += 1
			Ans += 1
			continue
		else:
			Ans -= 1
			break	

print(Ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = len(s)
ans = l//2
if l % 2 == 0:
    a,b = l//2 - 1, l//2
else:
    a,b = l//2, l//2

t = s[a:b+1]
while t == '1' * len(t) or t == '0' * len(t):
    ans += 1
    a -= 1
    b += 1
    if a < 0 or b >= l:break
    t = s[a:b+1]

print(ans)

Submission status: Accepted

Solution code:
def d_WideFlip(S):
    n = len(S)
    T = []  # 解説pdfにおけるT(S)の定義と同じもの
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  # 設問の文字列は1-indexedのため
    if len(T) > 0:
        return min(T)
    else:
        return n  # Sは0のみまたは1のみで構成されていた

S = input()
print(d_WideFlip(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__=="__main__":
    l = list(input())
    N = len(l)
    results = []
    for i in range(0,N-1):
        if not l[i]==l[i+1]:
            results.append(max(i+1,N-i-1))
    if len(results):
        print(min(results))
    else:
        print(N)

Submission status: Accepted

Solution code:
import math
S = input()
L = S[:math.ceil(len(S)/2)]
R = S[len(S)//2:]
#print(L, R)
if L[-1] == R[0]:
  j = 1
  i = 1
  while i < len(L):
    if R[0] == R[i] and L[-i-1] == R[i]:
      #print(-i-1, i)
      #print(L[-i-1], R[i])
      j += 1
      #print(j)
    else:
      break
    i+=1
    #print(i)
else:
  j = 0 
  
#print(j)
print(math.floor(len(S)/2) + j)

Submission status: Accepted

Solution code:
import sys

def solve1(s):
    n = len(s)
    i = 0
    while i <= n // 2:
        if s[n // 2] != s[n // 2 - i]:
            break
        if s[(n - 1) // 2] != s[(n - 1) // 2 + i]:
            break
        i += 1
    return (n - 1) // 2 + i


line = sys.stdin.readline().strip()
print(solve1(list(line)))

Submission status: Accepted

Solution code:
s = raw_input()

n = ans = len(s)

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 = raw_input()
n = len(s)
if n == 1:
    print 1
    exit()
if not n & 1:
    l = n / 2 - 1
    r = n / 2
    res = n / 2
    while r < n and l >= 0 and s[l] == s[r]:
        l -= 1
        r += 1
        res += 1
    print res
else:
    l = n / 2 - 1
    r = n / 2 + 1
    res = n / 2 + 1
    if s[n / 2] != s[l] or s[n / 2] != s[r]:
        print res
    else:
        while r < n and l >= 0 and s[l] == s[r]:
            l -= 1
            r += 1
            res += 1
        print res

Submission status: Accepted

Solution code:
A=list(map(int,list(input())))
L = len(A)
num = L
pre = A[0]
end = True
for i in range(1,L):
    if A[i] != pre:
        if i*2 < L and L - i < num:
            num = L - i
        elif i < num:
            num = i
    pre = A[i]
print(num)

Submission status: Accepted

Solution code:
import sys
l = list(raw_input())
if (not "0" in l) or (not "1" in l):
    print len(l)
    sys.exit()

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
mx = max(mx, min(i, len(l)-x))
print mx

Submission status: Accepted

Solution code:
S = input()
n = len(S)
j = 0
for i in range(1, n):
    if S[i - 1] != S[i]:
        if abs(n - 2 * i) < abs(n - 2 * j):
            j = i
print(max([j, n - j]))

Submission status: Accepted

Solution code:
S =str(input())
if len(S) % 2 == 1:
    a = 1
    b = int((len(S) - 1) / 2)
    while True:
        if b - a < 0:
            break
        if S[b] == S[b + a] and S[b] == S[b - a]:
            a = a + 1
        else:
            break
    c = a + b
    print(c)
else:
    d = 0
    e = int(len(S) / 2 - 1)
    f = S[e]
    if S[e + 1] == f:
        d = d + 1
    while True:
        if e - d < 0:
            break
        if S[e - d] == f and S[e + d + 1] == f:
            d = d + 1
        else:
            break
    g = d + e + 1
    print(g)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=[int(i) for i in input()]
L = len(S)


if L%2 == 1:
    mid = (L-1)//2
    midnum = S[mid]
    a = 0
    while mid-a != -1 and S[mid-a] == S[mid+a] == midnum:
        a += 1
    print(mid+a)
else:
    mid = (L-1)//2
    midnum1 = S[mid]
    midnum2 = S[mid+1]
    a = 0
    while mid-a != -1 and S[mid-a] == S[mid+1+a] == midnum1 == midnum2:
        a += 1
    print(mid+a+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-        

s = input()
l = []
r = []
len_s = len(s)
if(len_s==1):
    print(1)
else:
    for i in range(len_s-1):
        if(s[i]!=s[i+1]):
            l.append(i+1)
            r.append(len_s-i-1)
    if(len(l)==0):
        print(len_s)
    else:
        half = len(l)
        l.extend(r)
        l.sort()
        print(len_s-l[half-1])

Submission status: Accepted

Solution code:
import sys

S = input()
center = len(S) // 2

if len(S) % 2 == 1:
    b = S[center]
    for i in range(1, center + 1):
        if S[center + i] != b or S[center - i] != b:
            print(center + i)
            sys.exit()
else:
    b = S[center - 1]
    for i in range(center):
        if S[center - 1 - i] != b or S[center + i] != b:
            print(center + i)
            sys.exit()
print(len(S))

Submission status: Runtime Error

Solution code:
def main():
    S = input() + '.'
    count = 0
    data = []
    for i, s in enumerate(S[1:]):
        count += 1
        if s != S[i]:
            data.append(count)
            count = 0
    data.append(0)
    ans = max([min(data[i-1]+data[i], data[i]+data[i+1]) for i in range(1,len(data)-1)])
    print(ans)

main()

Submission status: Runtime Error

Solution code:
S = list(input())
lenS = len(S)
front = S.index('0' if S[0] == '1' else '1')
S.reverse()
end = S.index('0' if S[0] == '1' else '1')
ans = lenS - min(front, end)
print(ans)

Submission status: Runtime Error

Solution code:
s = list(map(int, list(input())))
ans = n
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: Runtime Error

Solution code:

import collections

s = raw_input() #100000000
stack = []
for l in s:
	if len(stack) == 0 or stack[-1][0] != l:
		stack.append([l, 1])
	else:
		stack[-1][1] += 1

def f(s):
	if len(s) == 1: return s[0]
	if len(s) == 2: return max(s)
	m = max([s[i] + s[i + 1] for i in range(len(s)-1)])
	for i in range(len(s)-1):
		if s[i] + s[i+1] == m:
			break
	qa = collections.deque(s[:i])
	qb = collections.deque([s[i+2:]])
	c = [s[i], s[i+1]]
	while(qa or qb):
		u = qa.pop() if qa else 0
		v = qb.popleft() if qb else 0
		c = c[::-1]
		c[0] += u
		c[1] += v
	return max(c)
	
print f([b for a,b in stack])

Submission status: Runtime Error

Solution code:

s = raw_input() #100000000
stack = []
for l in s:
	if len(stack) == 0 or stack[-1][0] != l:
		stack.append([l, 1])
	else:
		stack[-1][1] += 1

def f(s):
	if len(s) == 1:
		return s[0]
	if len(s) == 2:
		return max(s)

	m = 0
	for i in range(len(s)-1):
		m = max(m ,s[i] + s[i+1]) 
	r = +float('inf')
	for i in range(0,len(s)-1):
		if s[i] + s[i+1] == m:
			prefix = s[:i]
			if prefix:
				prefix[-1] += s[i + 1]
			suffix = s[i+2:]
			if suffix:
				suffix[0] += s[i] 

			r = min(r, m, f(prefix + suffix))
	return r
print f([b for a,b in stack])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()

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

print(a)

Submission status: Runtime Error

Solution code:
s = input()

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

n = len(sl)
res=[]

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

resu = n-1

while len(res) >1:
    resu = min(resu,max(res[0],res[1:]))
    x = res.pop(1)
    res[0]  = res[0]+x    
"""
    if res[0] > sum(res[1:]):
        resu = min(resu,res[0])
        x = res.pop(1)
        res[0] = res[0]+x
    else:
        resu = min(resu,sum(res[1:]))
        x = res.pop(1)
        res[0] =res[0]+x
"""
print(resu)

Submission status: Runtime Error

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000000)

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

Submission status: Runtime Error

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

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = list(input())
n = len(s)
ans = 1
# 区間は2以上の長さ
if n % 2 != 0:
    for i in range(1, n):
        a = s[n // 2]
        if s[n // 2 - 1 - i] != a or s[n // 2 + i] != a:
            print(n // 2 + i)
            exit()
else:
    for i in range(1, (n - 1) // 2 + 1):
        b = s[(n-1)//2]
        if s[(n - 1) // 2 - i] != b or s[(n - 1) // 2 + i] != b:
            print((n-1)//2+i)
            exit()
print(n)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
# 区間は2以上の長さ
if n % 2 != 0:
    for i in range(1, n):
        a = s[n // 2]
        if s[n // 2 - 1 - i] != a or s[n // 2 + i] != a:
            print(n // 2 + i)
            exit()
else:
    for i in range(1, (n - 1) // 2 + 1):
        b = s[(n-1)//2]
        if s[(n-1)//2-i] != b or s[(n-1)//2+i] != b:
            print((n - 1) / 2 + i)
            exit()
print(n)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
ans = 1
# 区間は2以上の長さ
if n % 2 != 0:
    for i in range(1, n):
        a = s[n // 2]
        if s[n // 2 - 1 - i] != a or s[n // 2 + i] != a:
            print(n // 2 + i)
            exit()

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

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split());print(len(bin(y//x))-2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


bool k_flip(string s, int k)
{
    int n = s.length();

    int status = 0;
    deque<int> endindex;

    rep(i, n - k + 1)
    {
        if (endindex.size() % 2 == 0 && s[i] == '1')
        {
            s[i] = '0';
            endindex.push_back(i + k - 1);
        }
        else if (endindex.size() % 2 == 1 && s[i] == '1')
        {
            s[i] = '0';
        }
        else if (endindex.size() % 2 == 1 && s[i] == '0')
        {
            endindex.push_back(i + k - 1);
        }

        if (endindex.front() == i)
            endindex.pop_front();
    }

    rep2(i, n - k + 1, n)
    {
        if (endindex.size() % 2 == 1)
        {
            if (s[i] == '0')
                s[i] = '1';
            else
                s[i] = '0';
        }

        if (endindex.front() == i)
            endindex.pop_front();
    }

    rep(i, k)
        if (s[i] == '1')
            status++;

    if (!status)
        return 1;
    else
        return 0;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    string s;
    cin >> s;
    int ok, ng, mid;

    if (k_flip(s, s.length()))
        cout << s.length() << endl;
    else
    {
        ok = 0, ng = s.length();
        while (ng - ok> 1)
        {
            mid = (ok + ng) / 2;
            if (k_flip(s, mid))
                ok = mid;
            else
                ng = mid;
            
        }
        cout << ok << endl;
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

bool k_flip(string s, int k)
{
    int n = s.length();

    int status = 0;
    deque<int> endindex;

    rep(i, n - k + 1)
    {
        if (endindex.size() % 2 == 0 && s[i] == '1')
        {
            s[i] = '0';
            endindex.push_back(i + k - 1);
        }
        else if (endindex.size() % 2 == 1 && s[i] == '1')
        {
            s[i] = '0';
        }
        else if (endindex.size() % 2 == 1 && s[i] == '0')
        {
            endindex.push_back(i + k - 1);
        }

        if (endindex.front() == i)
            endindex.pop_front();
    }

    rep2(i, n - k + 1, n)
    {
        if (endindex.size() % 2 == 1)
        {
            if (s[i] == '0')
                s[i] = '1';
            else
                s[i] = '0';
        }

        if (endindex.front() == i)
            endindex.pop_front();
    }

    rep(i, k)
        if (s[i] == '1')
            status++;

    if (!status)
        return 1;
    else
        return 0;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    string s;
    cin >> s;
    int ok, ng, mid;

    if (k_flip(s, s.length()))
        cout << s.length() << endl;
    else
    {
        ok = 0, ng = s.length();
        while (ng - ok> 1)
        {
            mid = (ok + ng) / 2;
            if (k_flip(s, mid))
                ok = mid;
            else
                ng = mid;
            
        }
        cout << ok << endl;
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
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)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
a=l.find("0")
b=l.rfind("0")
c=l.find("1")
d=l.rfind("1")
x=max(a,n-b-1)
y=max(c,n-b-1)
print(min(x,y,n-a,n-b))

Submission status: Runtime Error

Solution code:

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
#import random


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 = False
show_flg = True


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

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
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
    while i <= m:
        if l[i] == r[i] == base:
            i += 1
            cnt += 1
        else:
            break
    return cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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(X)>=3:
  if S[0]=='0':
    X.pop(0)
  if S[-1]=='0':
    X.pop(-1)
  P=(len(X)-1)//2
  
  answer= min(X[P-1]+X[P],X[P]+X[P+1])
elif len(X)==1:
  answer=X[0]
elif len(X)==2:
  answer=max(X)
print(answer)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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 = input()
N = len(S)

# ランレングス圧縮
A = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        A.append(cnt)
        cnt = 1
A.append(cnt)

# 例外処理
if len(A) <= 2:
    print(max(A))
    exit()

raise Exception
M = len(A)
ans = max(A[0], A[-1])
for i in range(1, M-1):
    ans = max(ans, min(A[i]+A[i-1], A[i]+A[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
s=list(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(asn,t)

print(ans)

Submission status: Runtime Error

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

print(ans)