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()
n = len(s)

l = 0
r = (n+1)//2 + 1

while r - l > 1:
    m = l + (r-l)//2
    d = n//2 - m
    if d == 0:
        if s[d:n-d].count("0") in [0, n-d*2]:
            l = m
        else:
            r = m
    else:
        if s[d:-d].count("0") in [0, n-d*2]:
            l = m
        else:
            r = m
if n % 2 == 0:
    print(n//2+l)
else:
    print(n//2+l+1)

Submission status: Wrong Answer

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

enc_list=[]
cnt=1
for i in range(1,len(slist)):
  if slist[i-1]==slist[i]:
    cnt+=1
  else:
    enc_list.append(cnt)
    cnt=1
else:
  enc_list.append(cnt)
#print(enc_list)

if len(enc_list)==1:
  print(enc_list[0])
elif len(enc_list)==2:
  print(max(enc_list[0],enc_list[1]))
else:
  print((len(slist)-1)//2+1)

Submission status: Wrong Answer

Solution code:
slist=list(map(int,list(input())))
len_s=len(slist)

if slist[0]==1:
  for i in range(len_s):
    slist[i]=1-slist[i]
#print(slist)

if sum(slist)==0:
  print(len_s)
else:
  first_turn=-1
  turn_twice=False
  for i in range(1,len_s):
    if slist[i-1]==0 and slist[i]==1:
      first_turn=i
    elif slist[i-1]==1 and slist[i]==0:
      turn_twice=True
      break
      
  if not turn_twice:
    print(max(first_turn,len_s-first_turn))
  else:
    enc_list=[]
    cnt=1
    for i in range(1,len_s):
      if slist[i-1]==slist[i]:
        cnt+=1
      else:
        enc_list.append(cnt)
        cnt=1
    else:
      enc_list.append(cnt)
    #print(enc_list)
    
    max_K=len_s
    for i in range(2,len(enc_list)):
      max_K=min(max_K,enc_list[i-2]+enc_list[i-1],enc_list[i-1]+enc_list[i])
    
    print(max_K)

Submission status: Wrong Answer

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

b=[int(S[i]) for i in range(N)]
for i in range(1,N):
    b[i]+=b[i-1]
black=[0 for i in range(0,N+1)]
for i in range(0,N):
    black[i+1]=b[i]


def condition(K):
    if 2*K-1<N:
        return True
    else:
        if black[K]-black[N-K]==0 or black[K]-black[N-K]==N-2*K:
            return True
        else:
            return False

start=1
end=N
while end-start>1:
    test=(end+start)//2
    if condition(test):
        start=test
    else:
        end=test

if condition(end):
    print(end)
else:
    print(start)

Submission status: Wrong Answer

Solution code:
#dame 
def main():
    S = input()
    r = len(S)
    if S.count('0') == r:
        return 0
    if S.count('1') == r:
        return r
    N = len(S)
    one = S[0] == '1'
    c = 0
    for i in range(N):
        if (S[i] == '1' and one) or (S[i] == '0' and not one):
            continue
        r = min(r, max(i, N-i))
        one = S[i] == '1'
    return r
print(main())

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    return S.count('0')
print(main())

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
ls=len(s)
if ls%2==0:
    tmp=0
    for i in range(ls//2):
        if s[ls//2+i]==s[ls//2-1-i]:
            tmp+=1
        else:
            break
    print(ls//2+tmp)
else:
    tmp=1
    for i in range(ls//2):
        if s[ls//2+1+i]==s[ls//2-1-i]:
            tmp+=1
        else:
            break
    print(ls//2+tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
print(max(s.count('0'), s.count('1')))

Submission status: Wrong Answer

Solution code:
s = list(input())
l = len(s)
if l == 1:
    print(1)
elif l % 2 == 0:
    for i in range(l//2):
        a = s[l//2]
        if s[l//2 - 1 - i] != a or s[l//2 + i] != a:
            print(l//2 + i)
            exit()
else:
    for i in range(1, (l-1)//2 + 1):
        a = s[(l-1)//2]
        if s[(l-1)//2 - i] != a or s[(l-1)//2 + i] != a:
            print((l-1)//2 + i)
            exit()
print(l)

Submission status: Wrong Answer

Solution code:
def find_cont(S):
    N=len(S)
    res=0
    idx=0
    for i in range(1,N):
        if S[idx]!=S[i]:
            res=max(res,i-idx)
            idx=i
    res=max(res,N-idx)
    return res
S=input()
N=len(S)
res = N//2 + N%2
res = max([res, find_cont(S)])
print(res)

Submission status: Wrong Answer

Solution code:
def find_cont(S):
    N=len(S)
    for i in range(N):
        if S[0]!=S[i]:
            return i
    return N
S=input()
N=len(S)
res = N//2 + N%2
res = max([res, find_cont(S), find_cont(S[::-1])])
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

c = Counter(input())
print(max(c.values()))

Submission status: Wrong Answer

Solution code:
#初めは0と1で多い方だと思った
#正確にやってはないけど連続する0or1より長くないとだめ
#上限が何かを考える
s=input()
l=len(s)

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

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
print(max(s.count("1"),s.count("0")))

Submission status: Wrong Answer

Solution code:
def solve(L, N):
    cur = 0
    LN = len(L)
    ans = N
    while cur < LN - 1:
        if L[cur] > 0 and L[cur + 1] < 0:
            ans = min(ans, L[cur] + abs(L[cur + 1]))
            L[cur + 1] *= -1
        elif L[cur] > 0 and L[cur + 1] > 0:
            L[cur + 1] += L[cur]
        cur += 1
    ans = min(ans, L[-1])
    return ans


S = input()
N = len(S)
L = []
cnt = 0
c = S[0]
for i, s in enumerate(S):
    sign = 1 if s == '1' else -1
    if c == s:
        cnt += sign
    else:
        L.append(cnt)
        cnt = sign
        c = s
else:
    L.append(cnt)

L2 = list(map(lambda x: -x, L))
ans1 = solve(L, N)
ans2 = solve(L2, N)


print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
ans = l
if len(set(list(S))) == 1 and S[0] == "0":
    print(0)
    exit()
for i in range(l-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(l-i-1,i+1))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    elif S[i] == S[i+1]:
        tmp += 1
    else:
        ans = max(ans,tmp+1)
        tmp = 0
print(max(2,ans))

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
tmp = 0
l = len(S)
for i in range(l-1):
    if i == l-2:
        ans = max(ans,tmp+1)
        tmp = 0
    elif S[i] == S[i+1]:
        tmp += 1
    else:
        ans = max(ans,tmp+1)
        tmp = 0
print(min(2,ans))

Submission status: Wrong Answer

Solution code:
import math
def f(s):
    ans=math.ceil(len(s)/2)
    p,q=0,0
    while q<len(s) and p<len(s)//2:
        if s[q]==s[p]:
            ans=max(ans,q)
            q+=1
        else: 
            p=q
            ans=max(ans,q)
    return ans



s=input()

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

Submission status: Wrong Answer

Solution code:
s = str(input())
n = len(s)
l = []

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

temp = 1
for i in range(1, n):
    if s[i] == s[i-1]:
        temp += 1
    else:
        l.append(temp)
        temp = 1
else:
    l.append(temp)
#print(l)

if len(l) == 1 or len(l) == 2:
    print(max(l))
    exit()
else:
    max_ = float('inf')
    for i in range(len(l)-1):
        max_ = min(max_, l[i]+l[i+1])
    print(max_)

Submission status: Wrong Answer

Solution code:
from collections import deque

S=input()
N=len(S)

prev=S[0]
ans=N
temp=0

con=deque()

for i in range(N):
    if S[i]==prev:
        temp+=1
    else:
        con.append(temp)
        prev=S[i]
        temp=1
con.append(temp)       
        
        
    
while len(con)>2:
    a=con[0]
    b=con[-1]
    if b>=a:
        con.popleft()
        con[0]+=con[1]
        ans=min(ans,N-a)
    else:
        con.pop()
        con[-1]+=con[-2]
        ans=min(ans,N-b)
    
    
    
if len(con)==2:
    ans=min(ans,max(con))
else:
    ans=N
    
    
print(ans)

Submission status: Wrong Answer

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

prev=S[0]
ans=N
temp=0

con=[]

for i in range(N):
    if S[i]==prev:
        temp+=1
    else:
        con.append(temp)
        prev=S[i]
        temp=1
con.append(temp)       
        
        
    
for i in range(len(con)-1):
    ans=min(ans,con[i]+con[i+1])
    
if len(con)==2:
    ans=max(con)
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
j = 0
m = S[0]
ls = []
for i in range(len(S)):
  if m!=S[i]:
    ls += [i-j]
    j = i
    m = S[i]
ls += [len(S)-j]
N = len(ls)
if N<3:
  print(max(ls))
else:
  ans = 0
  a = 0
  b = 0
  if N%2==0:
    for i in range(N):
      if i<N//2:
        a += ls[i]
      else:
        b += ls[i]
  else:
    for i in range(N):
      if i<N//2:
        a += ls[i]
      elif i>N//2:
        b += ls[i]
      else:
        a += ls[i]
        b += ls[i]
  ans = min(a,b)
  print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
j = 0
m = S[0]
ls = []
for i in range(len(S)):
  if m!=S[i]:
    ls += [i-j]
    j = i
    m = S[i]
ls += [len(S)-j]
if len(ls)<3:
  print(max(ls))
else:
  ans = 0
  for i in range(0,len(ls)-2):
    m = min(ls[i]+ls[i+1],ls[i+1]+ls[i+2])
    ans = max(ans,m)
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

LR = len(r)
answer = max(r[0][1], r[-1][1])
for i in range(1, LR - 1):
  answer = max(answer, r[i][1] + 1)
  
print(answer)

Submission status: Wrong Answer

Solution code:
# D - Wide Flip

S = input()

ans = float("inf")
N = len(S)

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

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
k = 10**9
if not "1" in s:
    print(0)
elif not "0" in s:
    print(n)
else:
    for i in range(n-1):
        if s[i] != s[i+1]:
            k = min(k,max(i+1,n-(i+1)))
    if k > n:
        print(n)
    else:
        print(k)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
k = 10**9
if not "1" in s:
    print(0)
elif not "0" in s:
    print(n)
else:
    for i in range(n-1):
        if s[i] != s[i+1]:
            k = min(k,max(i+1,n-(i+1)))

    print(k)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
k = 10**9

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

print(k)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from operator import add
S = input()
N = len(S)
G = [len(list(l)) for s, l in groupby(S)]
if len(G) == 1:
    print(N)
elif len(G) == 2:
    print(max(G))
else:
    print(max(map(add, G, G[1:])))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = input()
N = len(S)
G = [len(list(l)) for s, l in groupby(S)]
if len(G) == 1:
    print(N)
elif len(G) == 2:
    print(max(G[0],G[1]))
else:
    print(min(G[0]+G[1], G[-1]+G[-2]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

print(min(s))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

print(max(max(s), 2))

Submission status: Wrong Answer

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 = 0
        while True:
            if (center + c) < len(S) and S[center - c] == S[center + c] and S[center - c] == S[center - 1]:
                c += 1
            else:
                break
        print(c + center)
    else:
        c = 0
        while True:
            if (center + c) < len(S) and S[center - c] == S[center + c] and S[center] == S[center - c]:
                c += 1
            else:
                break
        print(c + center)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 = 0
        while True:
            if (center + c) < len(S) and S[center - c] == S[center + c] and S[center - c] == S[center - 1]:
                c += 1
            else:
                break
        print(c + center)
    else:
        c = 1
        while True:
            if (center + c) < len(S) and S[center - c] == S[center + c] and S[center] == S[center - c]:
                c += 1
            else:
                break
        print(c + center)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
ret = 0
itr = 0
search_s = -1

for s in S:
    if search_s == s:
        itr += 1
    else:
        ret = max(itr, ret)
        itr = 1
        search_s = s

ret = max(itr, ret)

ret = max(ret, 2)
print(ret)

Submission status: Wrong Answer

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

Solution code:
#!/usr/bin/env python3
import sys


def solve(S: str):
    print(S.count('0'))
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()

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

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

print(max(2, max(count_list)))

Submission status: Wrong Answer

Solution code:
s=input()
s+=str(2)
tmp=0
for i in range(len(s)):
    if s[i]=="0":
        cnt=0
        while s[i]==s[i+cnt] and i+cnt<len(s):
            cnt+=1
        tmp=max(tmp,cnt)
    elif s[i]=="1":
        cnr=0
        while s[i]==s[i+cnr] and i+cnr<len(s):
            cnr+=1
        tmp=max(tmp,cnr)

print(max(tmp,len(s)-tmp-1))

Submission status: Wrong Answer

Solution code:
s=input()
zero=0
one=0
for i in range(len(s)):
    if s[i]=="0":
        zero+=1
    else:
        one+=1

print(max(zero,one))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())

a = s.count("0")
b = s.count("1")

before = 0
if a == b:
    for ss in s:
        if ss == before:
            print(max(a,b))
            import sys
            sys.exit()
        before = ss
else:
    print(max(a,b))
    import sys
    sys.exit()
print(max(a,b)-1)

Submission status: Wrong Answer

Solution code:
s = list(input())

a = s.count("0")
b = s.count("1")

print(max(a,b))

Submission status: Wrong Answer

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

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

k = N

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

Submission status: Wrong Answer

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

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

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

M = len(A)
ans = 0
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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)
L = []
temp = S[0]
c = 1
for i in range(1, N-1):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
if S[N-1] == temp:
    c += 1
else:
    L.append(c)
    c = 1
L.append(c)

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

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)
L = []
temp = S[0]
c = 1
for i in range(1, N-1):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
if S[N-1] == temp:
    c += 1
else:
    L.append(c)
    c = 1
L.append(c)

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

Submission status: Wrong Answer

Solution code:
S = input().strip()
A = []
cur = 0
for i in range(1,len(S)):
    if S[i]==S[i-1]:
        continue
    else:
        A.append(i-cur)
        cur = i
A.append(len(S)-cur)
B = [0 for _ in range(len(A)+1)]
for i in range(1,len(A)+1):
    B[i] = B[i-1]+A[i-1]
cmax = 0
for i in range(len(A)):
    cl = max(B[i]-A[i],0)
    if i>0:
        cl = min(cl,A[i-1])
    cr = max(B[-1]-B[i+1]-A[i],0)
    if i<len(A)-1:
        cr = min(cr,A[i+1])
    cmax = max(cmax,cl+A[i],cr+A[i])
    
print(cmax)

Submission status: Wrong Answer

Solution code:
import math
S = input().strip()
cmax = 0
cur = 0
for i in range(1,len(S)):
    if S[i]==S[i-1]:
        continue
    else:
        cmax = max(cmax,i-cur)
        cur = i
cmax = max(cmax,len(S)-cur)
if cmax<=math.ceil(len(S)/2):
    print(math.ceil(len(S)/2))
else:
    print(cmax)

Submission status: Wrong Answer

Solution code:
S = input().strip()
cmax = 0
cur = 0
for i in range(1,len(S)):
    if S[i]==S[i-1]:
        continue
    else:
        cmax = max(cmax,i-cur)
        cur = i
cmax = max(cmax,len(S)-cur)
if cmax==1:
    print(2)
else:
    print(cmax)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC83 D

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC83 D

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

s = input()
n = len(s)
i = 0
lst = []
while i < n:
    if s[i] == '0':
        cnt = 1
        i += 1
        while i < n and s[i] == '0':
            cnt += 1
            i += 1
        lst.append(cnt)
    else:
        i += 1
if len(lst) == 0:
    print(n)
elif len(lst) == 1:
    print(lst[0])
else:
    print(min(lst)+1)

Submission status: Wrong Answer

Solution code:
S = input()

zero = 0
one = 0
for i in S:
    if i == "0":
        zero += 1
    else:
        one += 1
print(max(zero,one))

Submission status: Wrong Answer

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

count = []
pre = s[0]
c = 1
for t in s[1:] :
    if t == pre :
        c += 1
    else :
        count.append(c)
        pre = t
        c = 1

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

Submission status: Wrong Answer

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

count = []
pre = s[0]
c = 1
for t in s[1:] :
    if t == pre :
        c += 1
    else :
        count.append(c)
        pre = t
        c = 1

if len(count) == 1 and s[0] == '0' :
    print(0)
elif len(count) == 1 and s[0] == '1' :
    print(1)
elif len(count) == 2 :
    print(max(count))
else :
    print(max([count[i] + count[i+1] for i in range(len(count)-1)]))

Submission status: Wrong Answer

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

count = []
pre = s[0]
c = 1
for t in s[1:] :
    if t == pre :
        c += 1
    else :
        count.append(c)
        pre = t
        c = 1

if len(count) == 1 and s[0] == '0' :
    print(0)
elif len(count) == 1 and s[0] == '1' :
    print(1)
elif len(count) % 2 == 1 :
    print(min([count[i] + count[i+1] for i in range(len(count)-1)]))
else :
    count_ = [count[0]] + [count[i] + count[i+1] for i in range(len(count)-1)] + [count[-1]]
    print(max(min(count_[1:]), min(count_[:-1])))

Submission status: Wrong Answer

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

count = []
pre = s[0]
c = 1
for t in s[1:] :
    if t == pre :
        c += 1
    else :
        count.append(c)
        pre = t
        c = 1

if len(count) == 1 and s[0] == '0' :
    print(0)
elif len(count) == 1 and s[0] == '1' :
    print(1)
else :
    m = float('inf')
    for i in range(1, len(count)-1) :
        m = min(m, count[i] + count[i+1])
    print(max(min(m, count[0]), min(m, count[-1])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input();print(max(s.count("0"),s.count("1")))

Submission status: Wrong Answer

Solution code:
print(input().count("0"))