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:
s = input()
count = 1
maxc = 1
maxp = 0
smax = 10000000000

def switch01(s, start, end):
    s = list(s)
    s[start:end] = ['0']*(end-start)
    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) == 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)

Submission status: Wrong Answer

Solution code:
s = input()
count = 1
max = 1
maxp = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        if count > max:
            max = count
            maxp = i-count+1
        count = 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    s = map(int, sys.stdin.readline().strip())
    cnt = ([0, 0], [0, 0])
    for i in s:
        cnt[1][i] += 1
        cnt[0][i] = max(cnt[0][i], cnt[1][i])
        j = 1 - i
        cnt[0][j] = max(cnt[0][j], cnt[1][j])
        cnt[1][j] = 0

    print(max(cnt[0]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
c=len(S)/2


if N%2==1:
	cnt=c+1
	for i in range(1,c):
		if S[c-i]==S[c+i]==S[c]:
			cnt+=1
			pass
		else:
			break
else:
	cnt=c
	if S[c]!=S[c-1]:
		print cnt
		quit()
	cnt+=1
	for i in range(1,c):
		if S[c+i]==S[c-i-1]==S[c]:
			cnt+=1
		else:
			break

print cnt

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
TS=N
for k in range(N-1):
	if S[k]!=S[k+1]:
		TS=min(N, max(k+1, N-k-1))

print TS

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2
if N%2==1:
	center=S[n]

for i in range(n,N):
	#print N, n, i, N-i-1, S[n], S[i], S[N-i-1]
	if N%2==1:
		if S[i]==S[N-i-1]==center:
			pass
		else:
			print max( n, i-(N-i-1) )
			quit()
	else:
		if S[i]!=S[N-i-1]:
			print "a"
			print max( n, i-(N-i-1) )
			quit()		
else:
	print N

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2

for i in range(n,N):
	#print N,n,i,N-i-1, S[n], S[i], S[N-i-1]
	if S[i]!=S[N-i-1]:
		print max( n, i-(N-i-1) )
		quit()
	else:
		if N%2==1:
			if S[n]!=S[i]:
				print max( n, i-(N-i-1)-1 )
				quit()
else:
	if N%2==1:
		print n+1
	else:
		print n

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2

for i in range(n,N):
	#print N,n,i,N-i-1, S[n], S[i], S[N-i-1]
	if S[i]!=S[N-i-1]:
		print max( n, i-(N-i-1)-1 )
		quit()
else:
	if N%2==1:
		print n+1
	else:
		print n

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2

for i in range(n,N):
	#print n,i,N-i-1, S[n], S[i], S[N-i-1]
	if S[i]!=S[N-i-1]:
		print max( n, i-(N-i-1) )
		quit()
else:
	if N%2==1:
		print n+1
	else:
		print n

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2

for i in range(n,N):
	#print n,i,N-i-1, S[n], S[i], S[N-i-1]
	if S[n]==S[i]==S[N-i-1]:
		pass
	else:
		print max( n, i-(N-i-1) )
		quit()

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2
center=S[n]

for i in range(n,N):
	if S[i]!=S[N-i-1]:
		print max( n, i-(N-i-1) )
		quit()
	elif S[i]!=center:
		print max( n, i-(N-i-1) )
		quit()

Submission status: Wrong Answer

Solution code:
S=raw_input()
N=len(S)
n=len(S)/2

for i in range(n,N+1):
	temp_S=S[N-i:i]
	if len( set(temp_S) )==2:
		print i-1
		quit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=raw_input()
c=[]
cnt=0
for i in S:
	if i=="0":
		cnt+=1
	else:
		if cnt!=0:
			c.append(cnt)
			cnt=0
else:
	if cnt!=0:
		c.append(cnt)

if len(c)==0:
	print 1
elif len(c)==1:
	print c[0]
else:
	print max(c)+1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    minimum_t = 999999
    pre_letter = S[0]

    for idx in range(1, N):
        if S[idx] != pre_letter:
            minimum_t = min(max(idx, N-idx), minimum_t)
            pre_letter = S[idx]
        else:
            continue

    print(minimum_t)

main()

Submission status: Wrong Answer

Solution code:
S = input()
T = 10**5
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        K = max(i+1, len(S)-i-1)
        T = min(T, K)

print(T)

Submission status: Wrong Answer

Solution code:
def ans():
    S = input()
    N = len(S)
    if not ('1' in S and '0' in S):
        return print(N)

    tmp = 1000000
    for i, v in enumerate(S):
        if i == 0:
            continue
        if S[i-1] != v:
            tmp = min(max(i, N-i), tmp)
    return print(tmp)

Submission status: Wrong Answer

Solution code:
def ans():
    S = input()
    N = len(S)
    tmp = 1000000
    for i, v in enumerate(S):
        if i == 0:
            continue
        if S[i-1] != v:
            tmp = min(max(i, N-i), tmp)
    return print(tmp)

# main()
ans()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    N = len(S)
    if N == 1:
        return print('1')
    for k in range(N - 1, (N // 2) - 1, -1):
        first = S[0:k]
        union = k * 2 - N
        cut = first[-union:-1] + first[-1]
        if '1' in cut and '0' in cut:
            continue
        else:
            return print(k)


main()

Submission status: Wrong Answer

Solution code:
N = input()
a = N.count("0")
b = N.count("1")
print(max(a, b))

Submission status: Wrong Answer

Solution code:

import re

runs = re.compile("1+|0+")

def matchlen(m):
    start, end = m.span()
    return end - start

def foo(s):
    t = 'X' + s + 'X'
    ys = []
    xs = [m for m in runs.finditer(t)]
    for i, x in enumerate(xs):
        if i == 0 or i == len(xs) - 1:
            ys.append(matchlen(x))
        else:
            start, end = x.span()
            if matchlen(xs[i-1]) == 1 and matchlen(xs[i+1]) == 1 and (end + 2 < len(t) or start - 2 > 0):
                ys.append(end - start + 2)
            else:
                bonus = max(
                        min(matchlen(xs[i-1]), len(t) - end - 1),
                        min(matchlen(xs[i+1]), start - 1)
                        )
                ys.append(matchlen(x) + bonus)
    return max(ys)


if __name__ == "__main__":
    s = input()
    print(foo(s))

Submission status: Wrong Answer

Solution code:


import re

runs = re.compile("1+|0+")

def matchlen(m):
    start, end = m.span()
    return end - start

def foo(s):
    t = 'X' + s + 'X'
    ys = []
    xs = [m for m in runs.finditer(t)]
    for i, x in enumerate(xs):
        if i == 0 or i == len(xs) - 1:
            ys.append(matchlen(x))
        else:
            start, end = x.span()
            bonus = max(
                min(matchlen(xs[i-1]), len(t) - end -1), min(matchlen(xs[i+1]), start - 1)
            )
            ys.append(matchlen(x) + bonus)
    return max(ys)


if __name__ == "__main__":
    s = input()
    print(foo(s))

Submission status: Wrong Answer

Solution code:

def runLen(s, start):
    c = s[start]
    i = 0
    while start + i < len(s) and c == s[start + i]:
        i+= 1
    return i

def foo(s):
    pos = 0
    xs = []
    while pos < len(s):
        found = runLen(s, pos)
        if pos == 0 or pos + found == len(s):
            xs.append(found)
        else:
            xs.append(found+1)
        pos += found
    return max(xs)

if __name__ == "__main__":
    s = input()
    print(foo(s))

Submission status: Wrong Answer

Solution code:


def foo(s):
    return max(list(map(len, s.split('1'))) + list(map(len, s.split('0'))) + [2])

if __name__ == "__main__":
    s = input()
    print(foo(s))

Submission status: Wrong Answer

Solution code:
import numpy as np
import pdb
import copy

'''
larger one of 'number of 1' and 'number of 0' is
is definitely a lowerbound.
'''
def main():
    string = np.array(list(raw_input()))
    print minimum(string)

def minimum(string):
    num1s = len(np.where(string == '1')[0])
    num0s = len(np.where(string == '0')[0])
    return np.max([num1s, num0s])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(k)

Submission status: Wrong Answer

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

binary = input()
zeroone_list = [] # zero: minus, one: plus
prev_val = ''
count = -1
k = 0
for i in list(binary):
    if prev_val == i:
        if i == '0':
            zeroone_list[count] += -1
        else:
            zeroone_list[count] += 1
    else:
        if i == '0':
            zeroone_list.append(-1)
            prev_val = '0'
        else:
            zeroone_list.append(1)
            prev_val = '1'
        count += 1

while 1 < len(zeroone_list):
    if abs(zeroone_list[0]) >= abs(zeroone_list[-1]):
        zeroone_list[:-1] = map(lambda x:x * -1, zeroone_list[:-1])
        sums = sum(map(abs, zeroone_list[:-1]))
        if k < sums:
            k = sums
    else:
        zeroone_list[1:] = map(lambda x:x * -1, zeroone_list[1:])
        sums = sum(map(abs, zeroone_list[1:]))
        if k < sums:
            k = sums
    l = 0
    while l < len(zeroone_list) - 1:
        if zeroone_list[l] * zeroone_list[l + 1] > 0:
            zeroone_list[l] += zeroone_list[l + 1]
            zeroone_list.pop(l + 1)
            continue
        else:
            l += 1

print(k)

Submission status: Wrong Answer

Solution code:
S = input()

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

if len(tempT) == 0 and S[0] == "1":
    tempT.append(len(S))
elif len(tempT) == 0 and S[0] == "0":
    tempT.append(0)

T = min(tempT)

print(T)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0
maxCount = 0
for i in range(1,len(S)):
   if S[i] == "0" and S[i-1] == "0":
       count+=1
   elif S[i] == "1" and S[i-1] == "0":
       count+=1
       maxCount = max([maxCount, count])
       count = 0

count+=1
maxCount = max([maxCount, count])

if S.find("010") != -1 or S.find("101") != -1:
    print(2)
else:
    print(maxCount)

Submission status: Wrong Answer

Solution code:
import math

S = list(input())
n = 1
N = 100000

for i in range(1,len(S)):
    if S[i] == S[i-1]:
        n += 1
    else:
        if n < N:
            N = n
        n = 1
if N == 1:
    print(2)
else:
    print(N)

Submission status: Wrong Answer

Solution code:
import math

S = list(input())
n = 1
N = 100000

for i in range(1,len(S)):
    if S[i] == S[i-1]:
        n += 1
    else:
        if n < N:
            N = n
        n = 1
if n < N:
         N = n
if n == 1:
    print(2)
else:
    print(n)

Submission status: Wrong Answer

Solution code:
import math

S = list(input())
n = 1
N = 100000

for i in range(1,len(S)):
    if S[i] == S[i-1]:
        n += 1
    else:
        if n < N:
            N = n
        n = 1
if n == 1:
    print(2)
else:
    print(n)

Submission status: Wrong Answer

Solution code:
s = input()

def func(t, k, p):
    cnt = 0
    buf = 0
    arr = [0 for _ in t]
    arr.append(0)
    for i in range(len(t)) :
        if arr[i] == 1 :
            cnt -= 1
            buf += 1
        val = (int(t[i]) + cnt + buf)%2
        if val == p :
            if i+k > len(t) :
                if buf > 0 :
                    buf -= 1
                    continue
                else :
                    return False
            cnt += 1
            arr[i+k] += 1
    return True

def solve(t) :
    l, r = 1, len(t)+1
    while r-l > 1:
        mid = (r+l)//2
        # print(mid, func(mid))
        if func(t, mid, 1) or func(t, mid, 0) : l = mid
        else : r = mid
    return l

print(max(solve(s), solve(s[::-1])))

Submission status: Wrong Answer

Solution code:
s = input()

def func(k, p):
    cnt = 0
    buf = 0
    arr = [0 for _ in s]
    arr.append(0)
    for i in range(len(s)) :
        if arr[i] == 1 :
            cnt -= 1
            buf += 1
        val = (int(s[i]) + cnt + buf)%2
        if val == p :
            if i+k > len(s) :
                if buf > 0 :
                    buf -= 1
                    continue
                else :
                    return False
            cnt += 1
            arr[i+k] += 1
    return True

l, r = 1, len(s)+1
while r-l > 1:
    mid = (r+l)//2
    # print(mid, func(mid))
    if func(mid, 1) or func(mid, 0) : l = mid
    else : r = mid

print(l)

Submission status: Wrong Answer

Solution code:
s = input()

def func(k):
    cnt = 0
    buf = 0
    arr = [0 for _ in s]
    arr.append(0)
    for i in range(len(s)) :
        if arr[i] == 1 :
            cnt -= 1
            buf += 1
        val = (int(s[i]) + cnt + buf)%2
        if val == 0:
            if i+k > len(s) :
                if buf > 0 :
                    buf -= 1
                    continue
                else :
                    return False
            cnt += 1
            arr[i+k] += 1
    return True

l, r = 1, len(s)+1
while r-l > 1:
    mid = (r+l)//2
    # print(mid, func(mid))
    if func(mid) : l = mid
    else : r = mid

print(l)

Submission status: Wrong Answer

Solution code:
s = input()

def func(k):
    cnt = 0
    buf = 0
    arr = [0 for _ in s]
    arr.append(0)
    for i in range(len(s)) :
        if arr[i] == 1 :
            cnt -= 1
            buf += 1
        val = (int(s[i]) + cnt + buf)%2
        if val == 0:
            if buf > 0 :
                buf -= 1
                continue
            if i+k > len(s) : return False
            cnt += 1
            arr[i+k] += 1
    return True

l, r = 1, len(s)+1
while r-l > 1:
    mid = (r+l)//2
    # print(mid, func(mid))
    if func(mid) : l = mid
    else : r = mid

print(l)

Submission status: Wrong Answer

Solution code:
s = input()

def func(k):
    cnt = 0
    buf = 0
    arr = [0 for _ in s]
    arr.append(0)
    for i in range(len(s)) :
        if arr[i] == 1 :
            cnt -= 1
            buf += 1
        val = (int(s[i]) + cnt + buf)%2
        if val == 0:
            if buf > 0 :
                buf -= 1
                continue
            if i+k > len(s) : return False
            cnt += 1
            arr[i+k] += 1
    return True

l, r = 1, len(s)+1
while r-l > 1:
    mid = (r+l)//2
    print(mid, func(mid))
    if func(mid) : l = mid
    else : r = mid

print(l)

Submission status: Wrong Answer

Solution code:
s = input()

if all(x==s[0] for x in s):
    print(len(s))
    exit(0)

arr = []
pre = 0
for i in range(1,len(s)+1) :
    if i == len(s) or s[pre] != s[i] :
        arr.append(i-pre)
        pre = i

if len(arr) == 1:
    print(arr[0])
elif len(arr) == 2:
    if s[0]=='1' : print(arr[1])
    else : print(arr[0])
else:
    na = []
    for i in range(len(arr)-1) :
        na.append(arr[i] + arr[i+1])

    l, r = 0, len(na)
    if len(arr) == 3 and s[0]=='1':
        print(min(na))
    else :
        if s[0]=='1': l += 1
        if s[-1]=='1': r -= 1
        print(min(na[l:r]))

Submission status: Wrong Answer

Solution code:
s = input()

if all(x==s[0] for x in s):
    print(len(s))
    exit(0)

arr = []
pre = 0
for i in range(1,len(s)+1) :
    if i == len(s) or s[pre] != s[i] :
        arr.append(i-pre)
        pre = i

if len(arr) == 1:
    print(arr[0])
elif len(arr) == 2:
    if s[0]=='1' : print(arr[1])
    else : print(arr[0])
else:
    ans = len(s)
    for i in range(len(arr)-1) :
        ans = min(ans, arr[i] + arr[i+1])
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

if all(x==s[0] for x in s):
    print(len(s))
    exit(0)

arr = []
pre = 0
while s[pre] == '1' :
    pre += 1
for i in range(1,len(s)+1) :
    if i == len(s) or s[pre] != s[i] :
        arr.append(i-pre)
        pre = i

if len(arr) == 1:
    print(arr[0])
elif len(arr) == 2:
    print(min(arr))
else:
    ans = len(s)
    for i in range(len(arr)-1) :
        ans = min(ans, arr[i] + arr[i+1])
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
ans = 100000000
count = 1
for i in range(l-1):
	if S[i+1] != S[i]:
		tmp = max([i+1,l-i-1])
		ans = min([ans,tmp])

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import sys

s = sys.stdin.readline().strip()
check = [_s is "1" for _s in list(s)]
index = 0
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr != next:
        index = i+1
print(len(s) - index)

Submission status: Wrong Answer

Solution code:
s=input()
for i in range(1,len(s)):
    if len(set(s)) == 1 or (i>0 and  len(set(s[i:-i])) < 2):
        print(len(s)-i)
        break

Submission status: Wrong Answer

Solution code:
# AC
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
mx = max(mx, min(i, len(l)-x))
print mx

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def solve():
    
    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))
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

ans = 0

l = len(S)
front = S[0]
flag = 0
for i in range(1,l):
	if (front != S[i]):
		if (flag == 0):
			ans = max([ans,i,l-i])
			flag = 1
	else:
		flag = 0

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)
for i in range(N//2, N):
    if S[N-i:i] == '0'*(i-(N-i)) or S[N-i:i] == '1'*(i-(N-i)):
        K = i
print(K)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()

    len_ = len(S)
    if not S.count('0'):
        print(len_)
        return
    elif not S.count('1'):
        print(0)
        return

    k = len_// 2
    for i in range(len_ // 2):
        l = S[k - 1 - i]
        r = S[k]
        if l != r or k + i == len_:
            break

    if len_ & 1:
        print(k + 1 + i)
    else:
        print(k + i)

main()

Submission status: Wrong Answer

Solution code:
import math,sys

s=input()
k=math.ceil(len(s)/2)-1

if(s=='0'):
    print(0)
    sys.exit()
elif(s=='1'):
    print(1)
    sys.exit()

for i in range(int(math.ceil(len(s)/2))):
#    print(k+i,k-i)
    if(s[k+1] == s[k-1] and k-i == 0):
        k=k+i
        break
    elif(s[k+i] == s[k-i]):
        continue
    else:
        k=k+i
        break
print(k)

Submission status: Wrong Answer

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):
    a -= 1
    b += 1
    if a < 0 or b >= l:break
    ans += 1
    t = s[a:b+1]

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
count=1
counted=[]
ans=0

maxcount=0
if len(s)==1:
  print(1)
else:
    for i in range(1,len(s)):

        if s[i-1]==s[i]:
            count=count+1 
        else:
            counted.append(count)
            count=1
        if i==len(s)-1:
            counted.append(count)            
#    print(counted)
    answer=[]
    answer=counted[:]
    
    if len(counted)==1:
      print(counted[0])
    elif len(counted)==2:
      print(max(counted[0],counted[1]))  
        
    else:
      for i in range(1,len(answer)-1):
          if answer[i-1]+answer[i]+answer[i+1]>=ans: max_i=i
          ans=max(answer[i-1]+answer[i]+answer[i+1],ans)

      answer1=answer[max_i]
      for i in range(max_i):
          answer1=answer1+answer[i]
      answer2=answer[max_i]
      for i in range(max_i+1,len(answer)):
          answer2=answer2+answer[i]   
      print(min(ans,answer1,answer2))

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        judge = testmethod(slist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'
        list[i:i+k] = target

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        judge = testmethod(slist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

def testmethod(list, k):
    
    for i in range(0, len(list) - k):
        target = list[i:i+k]

        for t2 in range(len(target)):
            if target[t2] == '0':
                target[t2] = '1'
            else:
                target[t2] = '0'

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

    for k in range(len(slist)):
        judge = testmethod(slist, k)
        if judge == 0:
            max_k = k
        
    print(max_k)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    max_k = 0


    #バラバラ
    slist = []
    for i in range(len(s)):
        slist.append(s[i:i+1])

Submission status: Wrong Answer

Solution code:
s=input()
count=1
counted=[]
ans=0
pppp=0
answer_answer=1000000000000

if len(s)==1:
  print(1)
else:
    for i in range(1,len(s)):

        if s[i-1]==s[i]:
            count=count+1 
        else:
            counted.append(count)
            count=1
        if i==len(s)-1:
            counted.append(count)            
    answer=[]
    answer=counted[:]
    
    if len(counted)==1:
      print(counted[0])
    elif len(counted)==2:
      print(max(counted[0],counted[1]))          
    else:
      while len(answer)>3:
        for i in range(1,len(answer)-1):
            if answer[i-1]+answer[i]+answer[i+1]>=ans: max_i=i
            ans=max(answer[i-1]+answer[i]+answer[i+1],ans)
        
        if max_i!=len(answer)-2 and max_i!=1:
            answer[max_i+1]=answer[max_i+1]+answer[max_i+2]
            answer[max_i-1]=answer[max_i-1]+answer[max_i-2]
            del answer[max_i+2]
            del answer[max_i-2]
            
        elif max_i==len(answer)-2 and max_i!=1:
            answer[max_i-1]=answer[max_i-1]+answer[max_i-2]
            del answer[max_i-2]        
          
        elif max_i!=len(answer)-2 and max_i==1:
            answer[max_i+1]=answer[max_i+1]+answer[max_i+2]
            del answer[max_i+2]           
        
        answer_answer=min(answer_answer,ans)
        if  2*answer_answer<len(s): 
            pppp=1
            break
      if pppp==0: 
          print(min(answer_answer,answer[0]+answer[1],answer[1]+answer[2]))
      else:
          print(answer_answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def solution(S):
    while True:
        left = S.find("1")
        right = S.rfind("1")

        if left == right:
            if left == -1:
                return len(S)
            elif left == 0 or left == len(S) - 1:
                return len(S) - 1
            elif left == (len(S) - left - 1):
                return left + 1
            else:
                return max(left, len(S) - left - 1)
        else:
            next_S = ""
            for i in xrange(left, right + 1):
                next_S += ("0" if S[i] == "1" else "1")
            S = next_S

def main(argv):
    line = sys.stdin.readline()
    while line:
        S = line.rstrip("\n")
        print solution(S)
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

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

S = [int(x) for x in list(input())]

if len(S) == 1:
    print(1)

else:
    l = []
    c = 1
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            c += 1
        else:
            l.append(c)
            c = 1
    l.append(c)
    #print(l)
    
    lc = [l[j]+l[j+1] for j in range(len(l)-1)]
    if len(l) <= 2:
        print(max(l))
    else:
        print(max(lc))

Submission status: Wrong Answer

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

S = [int(x) for x in list(input())]

if len(S) == 1:
    print(1)

else:
    l = []
    c = 1
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            c += 1
        else:
            l.append(c)
            c = 1
    l.append(c)
    #print(l)
    
    lc = [l[j]+l[j+1] for j in range(len(l)-1)]
    if len(l) == 1:
        print(max(l))
    else:
        print(max(lc))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

s = input()
head = s[0]
end = s[-1]

maxhead = 0
maxend = 0
for i in s:
    if i == head:
        maxhead += 1
    else:
        break
for i in s[::-1]:
    if i == end:
        maxend += 1
print(max(maxhead, maxend))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def solution(S):
    while True:
        left = S.find("1")
        right = S.rfind("1")

        if left == right:
            if left == -1:
                return len(S)
            elif left == 0 or left == len(S) - 1:
                return len(S) - 1
            elif left == (len(S) - left - 1):
                return left + 1
            else:
                return max(left, len(S) - left - 1)
        else:
            S = "".join(map(
              lambda s: "0" if s == "1" else "1", S[left:right + 1]))

def main(argv):
    line = sys.stdin.readline()
    while line:
        S = line.rstrip("\n")
        print solution(S)
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = tuple(map(int, tuple(input())))
s = sum(S)
ls = len(S)
n = 0

if s is 0 or s is ls:
    print(ls)
else:
    n = 1
    while True:
        if n * 2 >= ls:
            break

        s = s - S[n - 1] - S[n * -1]
        if s is 0 or s is ls - 2 * n:
            break
        n += 1

    print(ls - n)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = tuple(map(int, tuple(input())))
s = sum(S)
ls = len(S)
n = 0

if s is 0 or s is ls:
    print(ls)
else:
    n = 1
    while True:
        print(n, s)
        if n * 2 >= ls:
            break

        s = s - S[n - 1] - S[n * -1]
        if s is 0 or s is ls - 2 * n:
            break
        n += 1

print(ls - n)

Submission status: Wrong Answer

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

S = [int(x) for x in list(input())]

if len(S) == 1:
    print(1)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = [int(x) for x in list(input())]

if len(S) == 1:
    print(1)

elif len(S) == 2:
    if S[0] == S[1]:
        print(2)
    else:
        print(1)
else:
    l = []
    c = 1
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            c += 1
        else:
            l.append(c)
            c = 1
    l.append(c)

    ans = max(l)
    if ans in l[1:-1]:
        print(ans + 1)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
M = len(S)
a = S.count("0")
b = S.count("1")

if "01"  in S and "10" in S:
    for i in range(1,M-1):
        if S[i] == "1":
            for j in range(i+1,M):
                if S[j] == "0":
                    P = max(i+1,len(S)-j+1)
                    ans = (max(ans,P))
else:
    ans = max(a,b)
print(ans)