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: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    x,y = LI()
    ans = 1
    for i in range(10000000000000):
        x *= 2
        if x > y:break
        ans += 1
    print(ans)

#D
def D():
    s = S()
    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)


#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    x,y = LI()
    ans = 1
    for i in range(10000000000000):
        x *= 2
        if x > y:break
        ans += 1
    print(ans)

#D
def D():
    s = S()
    n = len(s)
    c0 = s.count("0")
    c1 = n-c0
    if c0 == n or c1 == n:
        print(n)
        quit()
    if n%2:
        k = s[0]
        f = 0
        for i in range(n-1):
            if s[i] != s[i+1]:
                f = 1
                break
        if f and k not in s[i+1:]:
            print(max(i+1,n-i-1))
        else:
            print(n//2+1)
    else:
        k = s[0]
        f = 0
        for i in range(n-1):
            if s[i] != s[i+1]:
                f = 1
                break
        if f and k not in s[i+1:]:
            print(max(i+1,n-i-1))
        else:
            if s[n//2] == s[n//2+1]:
                print(n//2+1)
            else:
                print(n//2)


#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
s=input()
pre_b=s[0]
pre_e=s[-1]

n=len(s)
e=1
b=1
for i in range(1,n):
  #print(i,pre_b,s[i],pre_e,s[n-1-i])
  if pre_b==s[i]:
    b+=1
  else:
    pre_b='x'
  if pre_e==s[n-1-i]:
    e+=1
  else:
    pre_e='y'
ans=max(b,e)
print(max(2,ans))

Submission status: Wrong Answer

Solution code:
def wide_flip(S: str) -> int:
    min_k = float('inf')
    N = len(S)
    for i in range(N-1):
        if S[i] != S[i + 1]:
            min_k = min(min_k, max(i + 1, N - (i + 1)))
    return min_k


if __name__ == "__main__":
    S = input()
    ans = wide_flip(S)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())

    zero = [0, False]
    one = [0, False]

    s0 = S[0]
    c0 = 0
    c1 = 0

    for s in S:
        if s != s0:
            s0 = s
            if s == '0':
                c0 = 1
                c1 = 0
            else:
                c0 = 0
                c1 = 1
        else:
            if s == '0':
                c0 += 1
            else:
                c1 += 1

        if c0 >= zero[0]:
            if c0 == zero[0]:
                zero[1] = True
            else:
                zero[0] = c0
                zero[1] = False
        if c1 >= one[0]:
            if c1 == one[0]:
                one[1] = True
            else:
                one[0] = c1
                one[1] = False

    if zero[0] > one[0]:
        if zero[1]:
            print(zero[0] + 1)
        else:
            print(zero[0])
    elif one[0] > zero[0]:
        if one[1]:
            print(one[0] + 1)
        else:
            print(one[0])
    else:
        if zero[1] or one[1]:
            print(zero[0] + 1)
        else:
            print(zero[0])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    seq = []
    cur = ''
    cnt = 0
    for c in S:
        if c == cur:
            cnt += 1
        else:
            seq += [cnt]
            cur = c
            cnt = 1
    seq += [cnt, 0]
    ans = 0
    for i in range(1, len(seq)-1):
        ans = max(ans, min(seq[i-1] + seq[i], seq[i] + seq[i+1]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
cnt = 0
num0 = 0
num1 = 0
ans = 1000000000000
for i in range(0,L-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(i+1,L-(i+1)))
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
cnt = 0
num0 = 0
num1 = 0
for i in range(1,L):
    if S[i] == "0":
        num0 +=1
    else:
        num1 +=1
    if S[i-1] != S[i]:
        cnt+=1
S = sorted(S)
if cnt == 0:
    print(L)
elif cnt == 1:
    print(max(num0,num1))
else:
    print(2)
exit()

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
if l % 2:
    mid = l//2
    c = s[mid]
    ans = l
    for i in range(1, l//2+1):
        if s[l//2 - i] != c or s[1//2 + i] != c:
            ans = i + l//2
            break
else:
    if s[l//2-1] != s[l//2]:
        ans = l//2
    else:
        ans = l
        c = s[l//2]
        for i in range(1, l//2):
            if s[l//2 - i - 1] != c or s[1//2 + i] != c:
                ans = l//2 + i
                break
print(ans)

Submission status: Wrong Answer

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


if t % 2 == 0 :
    ans = t // 2
    th = t // 2
    if s[th-1] != s[th] :
        ans = th
    else :
        b = s[th]
        l = th - 1 - 1
        r = th + 1
        while l >= 0 and r <= t-1 and s[l] == b and s[r] == b :
            ans += 1
            l -= 1
            r += 1
else :
    ans = t // 2 + 1
    th = t // 2
    
    b = s[th]
    l = th - 1
    r = th + 1
    while l >= 0 and r <= t-1 and s[l] == b and s[r] == b :
        ans += 1
        l -= 1
        r += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
k = 0
tmp = set()
while k * 2 < n and len(tmp) < 2:
    print(k)
    tmp.add(s[n // 2 + k])
    tmp.add(s[(n - 1) // 2 - k])
    k += 1
print(n // 2 + k - (len(tmp) == 2))

Submission status: Wrong Answer

Solution code:
s = input()

n = len(s)
ans = 10**5
for i, (c1, c2) in enumerate(zip(s[:-1], s[1:])):
    if c1 == c2:
        continue
    ans = min(ans, max(i + 1, n - i - 1))

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
sums = sum([int(ss) for ss in s])

if sums == 0:
    print(0)
elif sums == len(s):
    print(len(s))
else:
    a = []
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            a.append(max(i+1, len(s)-i-1))
            
    print(min(a))

Submission status: Wrong Answer

Solution code:
s = list(input())
sums = sum([int(ss) for ss in s])

if sums == 0:
    print(0)
elif sums == len(s):
    print(len(s))
else:
    a = []
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            a.append(max(len(s[:i+1]), len(s[i+1:])))
            
    print(min(a))

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)%2==0:
  a = len(s)//2-1
  b = len(s)//2
else:
  a=b=len(s)//2
ans = b
cs = s[b]
while (a>0):
  if s[a] == cs and s[b] == cs:
    ans += 1
    a -= 1
    b += 1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)%2==0:
  a = len(s)//2-1
  b = len(s)//2
else:
  a=b=len(s)//2
ans = b
cs = s[b]
while (a>0):
  if s[a] == cs and s[b] == cs:
    ans += 1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)%2==0:
  a = len(s)//2-1
  b = len(s)//2
else:
  a=b=len(s)//2
ans = b
while (a<0):
  if s[a] == s[b]:
    ans += 1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
L = [0]
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    L.append(i + 1)
L.append(len(s))
LL = [0]
for i in range(len(L) - 1):
  LL.append(L[i+1] - L[i])
LL.append(0)
ma = 0
for i in range(len(LL) - 2):
  ma = max(ma,LL[i+1] + min(LL[i], LL[i+2]))

print(ma)

Submission status: Wrong Answer

Solution code:
S = str(input())
slist = list(S)
L = len(slist)
MIN = L
count = 0
for i in range(L):
    if i == 0:
        mae = slist[0]
    else:
        if slist[i]!=mae:
            count = max(i,L-i)
            if MIN >= count:
                MIN = count
            mae = slist[i]
        else:
            pass
if count == 0:
    print(int(slist[0]))
else:
    print(MIN)

Submission status: Wrong Answer

Solution code:
S = str(input())
slist = list(S)
L = len(slist)
MAX = 0
for i in range(L):
    if i == 0:
        mae = slist[0]
        count = 1
    else:
        if slist[i]!=mae:
            if MAX <= count and mae == "0":
                MAX = count
            count = 1
            mae = slist[i]
        else:
            count+=1
if MAX <= count and mae == "0":
    MAX = count
if MAX == 1:
    print(2)
else:
    print(MAX)

Submission status: Wrong Answer

Solution code:
S = str(input())
slist = list(S)
L = len(slist)
MAX = 0
for i in range(L):
    if i == 0:
        mae = slist[0]
        count = 1
    else:
        if slist[i]!=mae:
            if MAX <= count:
                MAX = count
            count = 1
            mae = slist[i]
        else:
            count+=1
if MAX <= count:
    MAX = count
if MAX == 1:
    print(2)
else:
    print(MAX)

Submission status: Wrong Answer

Solution code:
S = input()
max_zero = 0
cnt = 0
prev = ""
for s in S:
    if prev == "0" and s == "0":
        cnt += 1
        max_zero = max(max_zero, cnt)
    elif s == "0":
        cnt += 1
        max_zero = max(max_zero, cnt)
        prev = "0"
    else:
        prev = "1"
        cnt = 0
print(max_zero + 1if max_zero == 1 else max_zero)

Submission status: Wrong Answer

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

S = input()

l,r,r2 = 0,0,0
ans,prev = 0,0
while l < len(S):
    # prev,l,r,r2の4点で、3つの区間の情報を保持する
    if l == r == r2:
        while r < len(S) and S[l] == S[r]:
            r += 1
        r2 = r
    while r2 < len(S) and S[r] == S[r2]:
        r2 += 1
    # 今回区間
    sm = r - l
    # 前回区間
    prev_sm = l - prev
    # 次回区間
    nxt_sm = r2 - r
    # 両側に区間があれば追加
    sm += min(prev_sm, nxt_sm)
    ans = max(sm, ans)
    # 点を動かす
    prev = l
    l = r
    r = r2
print(ans)

Submission status: Wrong Answer

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

S = input()

l,r,r2 = 0,0,0
ans,prev = 0,0
while l < len(S):
    # prev,l,r,r2の4点で、3つの区間の情報を保持する
    if l == r == r2:
        while r < len(S) and S[l] == S[r]:
            r += 1
        r2 = r
    while r2 < len(S) and S[r] == S[r2]:
        r2 += 1
    # 今回区間
    sm = r - l
    # 前回区間
    prev_sm = l - prev
    # 次回区間
    nxt_sm = r2 - r
    # 両側に区間があれば追加候補
    add = min(prev_sm, nxt_sm)
    # 最大で現在区間分まで追加できる
    sm += min(add, sm)
    ans = max(sm, ans)
    # 点を動かす
    prev = l
    l = r
    r = r2
print(ans)

Submission status: Wrong Answer

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

S = input()

# 例外処理
if len(S) == 1:
    print(1)
    exit()

s = []
t = []
mx = tmp = 1
# 最後の文字をループ内で判定したいのでダミーを足しておく
S += 'a'
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        tmp += 1
    # 同じ文字が連続する最大箇所を探す
    elif tmp >= 2:
        if tmp > mx:
            mx = tmp
            # 始点と終点の情報と取っておく
            s = [i-mx]
            t = [i]
        # 同率なら両方残す
        elif tmp == mx:
            s.append(i-mx)
            t.append(i)
        tmp = 1
# ダミーを取り除く
S = S[:-1]

# 例外処理
if mx == 1 and len(S) >= 3:
    print(2)
    exit()

# 一番長く続いた箇所(複数の場合もある)について調べる
for i in range(len(s)):
    # 連続箇所の両端の先に文字があるかどうか
    if s[i]-1 >= 0 and t[i] < len(S):
        mx += 1
        break
print(mx)

Submission status: Wrong Answer

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

S = input()

# 例外処理
if len(S) == 1:
    print(1)
    exit()

s = []
t = []
mx = tmp = 1
# 最後の文字をループ内で判定したいのでダミーを足しておく
S += 'a'
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        tmp += 1
    # 同じ文字が連続する最大箇所を探す
    elif tmp >= 2:
        if tmp > mx:
            mx = tmp
            # 始点と終点の情報と取っておく
            s = [i-mx]
            t = [i]
        # 同率なら両方残す
        elif tmp == mx:
            s.append(i-mx)
            t.append(i)
        tmp = 1
# ダミーを取り除く
S = S[:-1]

# 例外処理
if mx == 1 and len(S) >= 3:
    print(2)
    exit()

ans = mx
# 一番長く続いた箇所(複数の場合もある)について調べる
for i in range(len(s)):
    tmp = mx
    # 添字調整
    if s[i]-2 >= 0:
        # 1文字前と2文字前が違えば+1
        if S[s[i]-1] != S[s[i]-2]:
            tmp += 1
    if t[i]+1 < len(S):
        # 1文字後と2文字後が違えば+1
        if S[t[i]] != S[t[i]+1]:
            tmp += 1
    ans = max(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
now = S[0]
cnt = 0
M = 0
nowM = 0
l = 0
L, R = 0, 0
nagasa = len(S)
for i in range( nagasa):
    if now == S[i]:
        cnt += 1
    else:
        if M < cnt:
            R = i
            L = l
            M = cnt
        elif M == cnt:
            if L == 0:
                L = l
                R = i
                M = cnt
        cnt = 1
        now = S[i]
        l = i
else:
    if M < cnt:
        R = nagasa
        L = l
        M = R-L
if L == 0 or R == nagasa:
    print(M)
else:
    print(M+1)

Submission status: Wrong Answer

Solution code:
s = list(map(int, list(input())))

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

ans = 10**5
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: Wrong Answer

Solution code:
S = input()
t = len(S)

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

if t == len(S) and S[0] == "0":
    print(0)
else:
    print(t)

Submission status: Wrong Answer

Solution code:
S = input()
if S == "1":
    print(1)
    exit(0)
elif S == "0":
    print(0)
    exit(0)
elif S == "00":
    print(0)
    exit(0)
elif S == "01":
    print(1)
    exit(0)
elif S == "11":
    print(2)
    exit(0)

t = 1
s = 2
for k in range(1,len(S)):
    if S[k-1] == S[k]:
        t += 1
        s = max(t,s)
    else:
        t = 1
if S[0] == "0" and s == len(S):
    print(0)
else:
    print(s)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
n = len(s)

fst = 0
lat = 0
ans = 0

if n % 2:
    fst = s[n//2::-1]
    lat = s[n//2:]
    ans = n//2 + 1

else:
    fst = s[n//2-1::-1]
    lat = s[n//2:]
    ans = n//2
  
for i in range(len(fst)-1):
    if fst[0] != lat[0]:
        break
    
    if fst[i+1] == fst[i] and lat[i+1] == lat[i]:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
S = raw_input()
maxl = 1
l = None
c = None
for i in S:
    if c == None:
        c = i
        l = 1
        continue
    if i == c:
        l += 1
        if maxl < l:
            maxl = l
    else:
        l = 1
        c = i
        continue
if maxl == 1:
    print(2)
else:
    print(maxl)

Submission status: Wrong Answer

Solution code:
s = input()

i_flips = []
i = 0
for j in range(1, len(s)):
    if s[j] != s[i]:
        i_flips.append(j)
        i = j
print(i_flips)

if len(i_flips) == 0:
    print(len(s))
else:
    ans = len(s)
    for i in i_flips:
        ans = min(ans, max(i, len(s)-i))
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

len_conti = []
i = 0
for j in range(1, len(s)):
    if s[j] != s[i]:
        len_conti.append(j-i)
        i = j
len_conti.append(len(s)-i)
# print(len_conti)

if len(len_conti) == 1:
    print(len(s))
elif len(len_conti) == 2:
    print(max(len_conti))
else:
    ks = [l1+l2 for l1, l2 in zip(len_conti[:-1], len_conti[1:])]
    print(min(ks))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=raw_input()
L=len(S)
ans=len(S)

if L%2==0: loop=L/2
else: loop=L/2+1

prev=None
for i in range(loop):
#	print i,L-i-1,S[i],S[L-i-1],S[i]==S[L-i-1],ans
	if S[i]==S[L-i-1]:
		if prev is None:
			pass
		elif prev!=S[i]:
			ans-=1
		prev=S[i]
	else:
		ans-=1

print ans

Submission status: Wrong Answer

Solution code:
S=raw_input()
L=len(S)
ans=len(S)

prev=None
for i in range(L/2):
#	print i,L-i-1,S[i],S[L-i-1],ans
	if S[i]==S[L-i-1]:
		if prev is None:
			pass
		elif prev!=S[i]:
			ans-=1
		prev=S[i]
	else:
		ans-=1

print ans

Submission status: Wrong Answer

Solution code:
S=raw_input()
L=len(S)

T=[0]
prev=0
for x in S:
	x=int(x)
	if prev==0 and x==1:
		v=T[-1]+1
	else:
		v=T[-1]
	T.append(v)
	prev=x

for i in range(L/2+1):
#	print i,L-i,T[i],T[L-i],S[i:L-i]
	if T[i]==T[L-i]:
		print L-i
		quit()
	elif (L-i)-i==1:
		print L-i

Submission status: Wrong Answer

Solution code:
S=raw_input()
L=len(S)

T=[0]
prev=0
for x in S:
	x=int(x)
	if prev==0 and x==1:
		v=T[-1]+1
	else:
		v=T[-1]
	T.append(v)
	prev=x

for i in range(L/2):
	if T[i]==T[L-i]:
		print L-i
		quit()
else:
	print (L+1)/2

Submission status: Wrong Answer

Solution code:
S=raw_input()
L=len(S)

T=[0]
prev=0
for x in S:
	x=int(x)
	if prev==0 and x==1:
		v=T[-1]+1
	else:
		v=T[-1]
	T.append(v)
	prev=x

for i in range(L/2):
	if T[i]==T[L-i]:
		quit()
else:
	print (L+1)/2

Submission status: Wrong Answer

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

print(K)

Submission status: Wrong Answer

Solution code:
S=raw_input()

ans=0
cnt=0
prev=-1

for x in S:
	if prev==x:
		cnt+=1
		prev=x
	else:
		ans=max(ans,cnt)
		cnt=1
		prev=x
else:
	ans=max(ans,cnt)

if ans==1:
	if len(S)==1:
		print ans
	else:
		print ans+1
else:
	print ans

Submission status: Wrong Answer

Solution code:
s = input()
if len(s)==1:
  print(1)
  exit()
zoku0 = 1
zoku1 = 1
kae = 0
for i in range(len(s)):
  a = s[i]
  b = s[i-1]
  if a == b:
    if a == "1":
      zoku1 +=1
    else:
      zoku0 +=1
print(max(zoku1,zoku0,kae))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

AA = list(map(int,list(input())))
L = len(AA)
ans = INF
for i in range(1,L):
	if AA[i] != AA[i-1]:
		ans = min(ans,max(L-i,i))

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    c = 0
    s0 = list(filter(lambda x: x, S.split('1')))
    s1 = list(filter(lambda x: x, S.split('0')))

    t = []
    SS = []
    for c in S:
        if len(t) == 0 or t[0] == c:
            t.append(c)
        else:
            SS.append(t)
            t = [c]
    if len(t) != 0:
        SS.append(t)
    SS = list(map(lambda x: len(x), SS))

    if len(SS) <= 2:
        return max(SS)

    ans = sys.maxsize
    while len(SS) > 2:
        l = SS[0] + SS[1]
        r = SS[-1] + SS[-2]
        m = len(S) - SS[0] - SS[-1]
        if l >= r:
            if l >= m:
                # print('l')
                ans = min(ans, l)
                SS = [SS[0], SS[1] + SS[2]] + SS[3:]
            else:
                # print('m', l, r, m)
                ans = min(ans, m)
                SS = [SS[0] + SS[1]] + SS[2:-2] + [SS[-2] + SS[-1]]
        else:
            if r >= m:
                # print('r')
                ans = min(ans, r)
                SS = SS[:-3] + [SS[-3] + SS[-2], SS[-1]]
            else:
                # print('m', l, r, m)
                ans = min(ans, m)
                SS = [SS[0] + SS[1]] + SS[2:-2] + [SS[-2] + SS[-1]]

    return ans


def main():
    S = read_str().strip()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = list(input())
left = 1
right = len(S)-left
min_len = len(S)
pre_left = 0
while(left!=len(S) and right!=0 and pre_left!=left):
	pre_left = int(left)
	for i in range(left,len(S)):
		if(S[i-1] == S[i]):
			left += 1
			right = len(S)-left

		else:
			break

	if(left>=right):
		if(min_len>left):
			min_len = int(left)

	elif(left<right):
		if(min_len>right):
			min_len = int(right)

print(min_len)

Submission status: Wrong Answer

Solution code:
S = list(input())
left = 1
right = len(S)-left
min_len = 10000000
pre_left = 0
while(left!=len(S) and right!=0 and pre_left!=left):
	pre_left = int(left)
	for i in range(left,len(S)):
		if(S[i-1] == S[i]):
			left += 1
			right = len(S)-left

		else:
			break

	if(left>=right):
		if(min_len>left):
			min_len = int(left)

	elif(left<right):
		if(min_len>right):
			min_len = int(right)

print(min_len)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

S = list(map(int, input()))

#max_S = 0
#count = 1
#flag = 0
#
#for i in range(1, len(S)):
#    if S[i-1]==S[i]:
#        count += 1
#    else:
#        if max_S < count:
#            max_S = count
#        count = 1
#        flag += 1
#
#if max_S < count:
#    max_S = count
#
#if flag < 2:
#    max_S -= 1

N = len(S)

if sum(S) < 1:
    min_T = 0
else:
    min_T = N
    for i in range(1, N):
        if S[i]!=S[i-1]:
            min_T = min(min_T, max(i, N-i))

print(min_T)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

S=list(input())

#max_S = 0
#count = 1
#flag = 0
#
#for i in range(1, len(S)):
#    if S[i-1]==S[i]:
#        count += 1
#    else:
#        if max_S < count:
#            max_S = count
#        count = 1
#        flag += 1
#
#if max_S < count:
#    max_S = count
#
#if flag < 2:
#    max_S -= 1

N = len(S)

if int("".join(S)) < 1:
    min_T = 0
else:
    min_T = N
    for i in range(1, N):
        if S[i]!=S[i-1]:
            min_T = min(min_T, max(i, N-i))

print(min_T)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

S=list(input())

#max_S = 0
#count = 1
#flag = 0
#
#for i in range(1, len(S)):
#    if S[i-1]==S[i]:
#        count += 1
#    else:
#        if max_S < count:
#            max_S = count
#        count = 1
#        flag += 1
#
#if max_S < count:
#    max_S = count
#
#if flag < 2:
#    max_S -= 1

N = len(S)

if int("".join(S)) < 1:
    min_T = 0
else:
    min_T = N
    for i in range(N-1):
        if not S[i]==S[i+1]:
            T = max(i+1, N-i-1)
            if T<min_T:
                min_T = T

print(min_T)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

S=list(input())

#max_S = 0
#count = 1
#flag = 0
#
#for i in range(1, len(S)):
#    if S[i-1]==S[i]:
#        count += 1
#    else:
#        if max_S < count:
#            max_S = count
#        count = 1
#        flag += 1
#
#if max_S < count:
#    max_S = count
#
#if flag < 2:
#    max_S -= 1

N = len(S)

if int("".join(S)) < 1:
    min_T = 0
else:
    min_T = N
    for i in range(N-1):
        if not S[i]==S[i+1]:
            T = max(i, N-i)
            if T<min_T:
                min_T = T

print(min_T)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

S=list(input())

max_S = 0
count = 1
flag = 0

for i in range(1, len(S)):
    if S[i-1]==S[i]:
        count += 1
    else:
        if max_S < count:
            max_S = count
        count = 1
        flag += 1

if max_S < count:
    max_S = count

if flag < 2:
    max_S -= 1

if int("".join(S)) < 1:
    max_S = -1

print(max_S+1)

Submission status: Wrong Answer

Solution code:
s = [int(x) for x in input()]

for k in range(len(s)//2 + 1, len(s)+1):
    if (not all(s[len(s)-k:k])) and any(s[len(s)-k:k]):
        print(k - 1)
        break

Submission status: Wrong Answer

Solution code:
S = input()

# s = S[0]
temp_T = 100000
for i in range(len(S)-1):
    if(S[i] != S[i+1]):
        judge = max(i+1,len(S)-(i+1))
        temp_T = min(judge, temp_T)
        s = S[i]

print(temp_T)

Submission status: Wrong Answer

Solution code:
S = input()

# s = S[0]
temp_T = 100000
for i in range(len(S)-1):
    if(S[i+1] != S[i]):
        judge = max(i+1,len(S)-(i+1))
        temp_T = min(judge, temp_T)
        s = S[i]

print(temp_T)

Submission status: Wrong Answer

Solution code:
S = input()

s = S[0]
temp_T = 100000
for i in range(1, len(S)):
    if(S[i] != s):
        judge = max(i,len(S)-i-1)
        temp_T = min(judge, temp_T)
        s = S[i]

print(temp_T)

Submission status: Wrong Answer

Solution code:
S = input()

s = S[0]
temp_T = 100000
for i in range(1, len(S)):
    if(S[i] != s):
        judge = max(i,len(S)-i)
        temp_T = min(judge, temp_T)
        s = S[i]

print(temp_T)

Submission status: Wrong Answer

Solution code:
s = list(input())


def circular_list(list):
    index = 0
    while True:
        yield list[index]
        index = (index + 1) % len(list)


a = circular_list(s)

prev_char = ""
next_char = ""

maximize = 0
count = 1

for index in range(len(s)*2):
    if index == 0:
        prev_char = a.__next__()
    next_char = a.__next__()

    # print(index, prev_char, next_char, count)
    if(prev_char != next_char):
        maximize = max(maximize, count)
        count = 1
        prev_char = next_char
    else:
        count += 1

maximize = max(maximize, count)

if maximize == len(s)+1:
    print(maximize-1)
else:
    print(maximize)

Submission status: Wrong Answer

Solution code:
s = list(input())


def circular_list(list):
    index = 0
    while True:
        yield list[index]
        index = (index + 1) % len(list)


a = circular_list(s)

prev_char = ""
next_char = ""

maximize = 0
count = 1

for index in range(len(s)+1):
    if index == 0:
        prev_char = a.__next__()
    next_char = a.__next__()

    # print(index, prev_char, next_char, count)
    if(prev_char != next_char):
        maximize = max(maximize, count)
        count = 1
        prev_char = next_char
    else:
        count += 1

maximize = max(maximize, count)

if maximize == len(s)+1:
    print(maximize-1)
else:
    print(maximize)

Submission status: Wrong Answer

Solution code:
S = input()
a = [1,]

for i in range(1, len(S)):
    if S[i] == S[i-1]:
        a[-1] += 1
    else:
        a.append(1)

amax = max(a)

if amax == 1:
    print(2)
else:
    print(amax)

Submission status: Wrong Answer

Solution code:
s = input()
count = 1
maxc = 1
maxp = 0
smax = 10000000000

def switch01(s, start, end):
    s = list(s)
    for i in range(start,end):
        if s[i] == '1':
            s[i] = '0'
        else:
            s[i] = '1'
    return ''.join(s)



while True:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            count += 1
        else:
            if count > maxc:
                maxc = count
                maxp = i-count+1
            count = 1
    tmp = [maxp,maxc,len(s)-maxc-maxp]
    if max(tmp) == len(s):
        break
    if max(tmp) == maxp:
        if smax > max(tmp):
            smax = max(tmp)
        s = switch01(s,0,maxp)
    elif max(tmp) == maxc:
        if smax > max(tmp):
            smax = max(tmp)
        s = switch01(s,maxp,maxp+maxc)
    else:
        if smax > max(tmp):
            smax = max(tmp)
        s = switch01(s,maxp+maxc,len(s))
            
    if s == '0'*len(s) or s == '1'*len(s):
        break
        
print(smax)