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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


i=0
res=0
while(i<N):
    j=i
    b=s[i]
    while(j<N and s[j]==b):
        j+=1
    res=max(res,j-i)
    i=j

print(max((len(s)+1)//2,res))

Submission status: Wrong Answer

Solution code:
def check(b):
    isok=True
    ch=False
    for c in s:
        if (not ch) and (c!=str(b)):
            ch=True
            b=b^1
        elif c!=str(b):
            isok=False
            break
    return isok

s=input()

if check(1) or check(0):
    print(max(s.count('1'),s.count('0')))
    exit()
print((len(s)+1)//2)

Submission status: Wrong Answer

Solution code:
def check(b):
    isok=True
    ch=False
    for c in s:
        if (not ch) and (c!=str(b)):
            ch=True
            b=b^1
        elif c!=str(b):
            isok=False
            break
    return isok

s=input()

if check(1) or check(0):
    print(max(s.count('1'),s.count('0')))
    exit()
print(len(s)+1//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())

n = len(s)

if set(list(s)) == 1:
    print(n)
    exit()

def is_ok(x):
    for i in range(n-x, x-1):
        if s[i] != s[i+1]:
            return False
    else:
        return True 



l = 1
r = n
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        l = c
    else:
        r = c
print(l)

Submission status: Wrong Answer

Solution code:
s = list(input())
if '0' not in s or '1' not in s:
    print(len(s))
    exit()

if s[0] == s[-1]:
    cnt = 0
    for i in range(len(s)):
        if s[i] == s[0]:
            cnt += 1
        else:
            break

    for i in range(len(s)-1,-1,-1):
        if s[i] == s[0]:
            cnt += 1
        else:
            break
    print(cnt)

else:
    cnt_l = 0
    for i in range(len(s)):
        if s[i] == s[0]:
            cnt_l += 1
        else:
            break

    cnt_r = 0
    for i in range(len(s)-1,-1,-1):
        if s[len(s)-1] == s[i]:
            cnt_r += 1
        else:
            break

    cnt = max(cnt_l,cnt_r)
    print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()

n = len(S)
ans = n
ans2 = n

for i in range(n):
    if S[i] == "1":
        ans = min(ans, max(n-i-1, i))
    else:
        ans2 = min(ans, max(n-i-1, i))


print(max(ans, ans2))

Submission status: Wrong Answer

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

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


print(ans)

Submission status: Wrong Answer

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

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


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n % 2 == 0:
    ans = n // 2
    tmp = set()
    x = n // 2 - 1
    for cnt in range(0, n // 2):
        tmp.add(s[x-cnt])
        tmp.add(s[x+1+cnt])
        if len(tmp) == 2:
            ans = cnt
            break

    print(ans + n // 2)

else:
    x = n // 2
    tmp = {s[x]}
    ans = n // 2
    for cnt in range(1, n // 2 + 1):
        tmp.add(s[x-cnt])
        tmp.add(s[x+cnt])
        if len(tmp) == 2:
            ans = cnt
            break
    print(ans + n // 2)

Submission status: Wrong Answer

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

if n % 2 == 0:
    tmp = set()
    x = n // 2 - 1
    cnt = 0
    while len(tmp) < 2 and cnt < n // 2:
        tmp.add(s[x-cnt])
        tmp.add(s[x+1+cnt])
        cnt += 1

    print(cnt - 1 + n // 2)

else:
    x = n // 2
    tmp = {s[x]}
    cnt = 0
    while len(tmp) < 2 and cnt < n // 2:
        tmp.add(s[x-cnt])
        tmp.add(s[x+cnt])
        cnt += 1
    print(cnt - 1 + (n + 1) // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()

print(max(s.count('0'),s.count('1')))

Submission status: Wrong Answer

Solution code:
s = input()
a = s[0]
e = s[-1]
chk = [0]
l = len(s)
  
for i in range(l-1):
  if s[i] != s[i+1]:
    chk.append(i+1)
    
if a == e:
  chk.append(l)
  L = chk[:len(chk)//2]
  R = chk[len(chk)//2:]
  ab = [y-x for x,y in zip(L,R)]
  ans = min(ab)
  
if a != e:
  L = chk[:len(chk)//2]
  R = chk[len(chk)//2:]
  ab = [y-x for x,y in zip(L,R)]
  ans = min(ab)
  
  chk = chk[1:]
  chk.append(l)
  L = chk[:len(chk)//2]
  R = chk[len(chk)//2:]
  ab = [y-x for x,y in zip(L,R)]
  ans = max(ans,min(ab)) 
  
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()

sets=set(s)
if len(sets)==1:
    print(len(s))
    exit()

if len(s)==1 or len(s)==2:
    print(1)
    exit()

lis=[]
cnt=1
last=s[0]
for i in range(1,len(s)):
    if last != s[i]:
        lis.append(cnt)
        last=s[i]
        cnt=0
    cnt+=1

lis.append(cnt)
if len(lis)==2:
    print(max(lis))
    exit()


ind=-1
mx=-1
for i in range(len(lis)-1):
    if mx < lis[i]+lis[i+1]:
        mx= lis[i]+lis[i+1]
        ind=i

lis1=lis[:ind+1]
lis2=lis[ind+1:]
print(max(sum(lis1),sum(lis2)))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
ans = n

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import collections
    S = list(map(int, list(input())))
    N = len(S)

    l = 1
    r = N+1

    while(l+1 < r):
        mid = (l+r) // 2
        q = collections.deque()
        count = 0
        flag = True
        for i in range(N):
            if (S[i] + count) % 2 == 0:
                continue
            else:
                if count and i - q[0] >= mid:
                    count -= 1
                    q.popleft()
                else:
                    if N - i >= mid:
                        q.append(i)
                        count += 1
                    else:
                        flag = False
                        break
        if flag:
            l = mid
        else:
            r = mid
    ans = l

    for i in range(N):
        S[i] ^= 1

    l = 1
    r = N+1

    while(l+1 < r):
        mid = (l+r) // 2
        q = collections.deque()
        count = 0
        flag = True
        for i in range(N):
            if (S[i] + count) % 2 == 0:
                continue
            else:
                if count and i - q[0] >= mid:
                    count -= 1
                    q.popleft()
                else:
                    if N - i >= mid:
                        q.append(i)
                        count += 1
                    else:
                        flag = False
                        break
        if flag:
            l = mid
        else:
            r = mid

    ans = max(ans, l)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = [int(i) for i in STR()]
ans = inf
n = len(s)
i = 0
ans = inf
while i < n:
    tmp = 0
    for j in range(i, n):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    ans = min(ans, max(tmp, n - tmp))
    i += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import collections
    S = list(map(int, list(input())))
    N = len(S)
    ans = N
    count = 0
    id = 0

    if S[0] == 0:
        for i in range(N):
            S[i] ^= 1

    l = 1
    r = N+1

    while(l+1 < r):
        mid = (l+r) // 2
        q = collections.deque()
        count = 0
        flag = True
        for i in range(N):
            if (S[i] + count) % 2 == 0:
                continue
            else:
                if count and i - q[0] >= mid:
                    count -= 1
                    q.popleft()
                else:
                    if N - i >= mid:
                        q.append(i)
                        count += 1
                    else:
                        flag = False
                        break
        if flag:
            l = mid
        else:
            r = mid

    print(l)


main()

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = [int(i) for i in STR()]
ans = inf
n = len(s)
i = 0
ans = 0
while i < n:
    tmp = 0
    for j in range(i, n):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    ans = max(ans, max(tmp, n - tmp))
    i += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import collections
    S = list(map(int, list(input())))
    N = len(S)
    ans = N
    count = 0
    id = 0

    if S[0] == 0:
        for i in range(N):
            S[i] ^= 1

    l = 1
    r = N

    while(l+1 < r):
        mid = (l+r) // 2
        q = collections.deque()
        count = 0
        flag = True
        for i in range(N):
            if (S[i] + count) % 2 == 0:
                continue
            else:
                if q and i - q[0] >= mid:
                    count -= 1
                    q.popleft()
                else:
                    if N - i >= mid:
                        q.append(i)
                        count += 1
                    else:
                        flag = False
                        break

        if flag:
            l = mid
        else:
            r = mid

    print(l)


main()

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = [int(i) for i in STR()]
ans = inf
n = len(s)
i = 0
flag = False #反転フラグ
while i < n - 1:
    if s[i] == 0 or (flag and s[i] == 1): #全反転する
        flag = not flag
        ans = min(ans, n - i + 1)
    
    idx = i
    for j in range(i, n):
        if s[j] != s[i]:
            break
        else:
            idx = j
    if idx == i:
        for j in range(i + 1, n):
            #print(j, s[j], s[j] == s[i])
            if s[j] == s[i]:
                break
            else:
                idx = j
        ans = min(ans, idx - i + 1)
        #print('a', i, idx, ans, flag)
        #flag = not flag
        i += 1
    else:
        ans = min(ans, idx - i + 1)
        #print('b', i, idx, ans, flag)
        i = idx + 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
if int(s) == 0:
    print(0)
    exit()
cnt_max = 1
cnt = 1
cnt_list = deque([])
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        cnt += 1
    else:
        cnt_list.append(cnt)
        cnt_max = max(cnt, cnt_max)
        if i == len(s) - 1:
            continue
        cnt = 1
cnt_list.append(cnt)
# print(cnt_list)
cnt_max = max(cnt, cnt_max)
if len(cnt_list) == 1:
    ans = 1
elif cnt_max == 1:
    if len(s) < 3:
        ans = cnt_max
    else:
        ans = cnt_max + 1
else:
    ans = cnt_max
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))
N = len(S)
ans = N
count = 0
id = 0

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

    elif i == N-1:
        ans = min(ans, i - id)


print(ans)

Submission status: Wrong Answer

Solution code:
S = list(map(int, input()))
N = len(S)

cnt = []
now = -1
for s in S:
    if s != now:
        now = s
        cnt.append(0)
    cnt[-1] += 1

print(max(max(cnt), -(-N // 2)))

Submission status: Wrong Answer

Solution code:
S = list(map(int, input()))
N = len(S)

cnt = []
now = -1
for s in S:
    if s != now:
        now = s
        cnt.append(0)
    cnt[-1] += 1

if len(cnt) <= 2:
    print(max(cnt))
    exit()

print(-(-N // 2))

Submission status: Wrong Answer

Solution code:
S = list(map(int, list(input())))
N = len(S)
ans = 1
count = 0
for i in range(1, N-1):
    if S[i] == S[i-1]:
        count += 1

    else:
        count = 1
    ans = max(ans, count)


print(ans+1)

Submission status: Wrong Answer

Solution code:
def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


s = input()
n = len(s)

a = []
b = []
for i in range(n - 1):
    if s[i] != s[i + 1]:
        a.append(i + 1)
        b.append(n - i - 1)

if not a:
    print(n)
    exit()

    
a1 = make_divisors(a[0])
b1 = make_divisors(b[0])

for divisor in a1[::-1]:
    for i in range(len(a)):
        if a[i] % divisor == 0 or b[i] % divisor == 0:
            pass
        else:
            break
    else:
        ans1 = divisor
        break

for divisor in b1[::-1]:
    for i in range(len(a)):
        if a[i] % divisor == 0 or b[i] % divisor == 0:
            pass
        else:
            break
    else:
        ans2 = divisor
        break

if s[i] == "1":
    print(ans1)
elif s[i] == "0":
    print(ans2)

Submission status: Wrong Answer

Solution code:
def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


s = input()
n = len(s)

a = []
b = []
for i in range(n - 1):
    if s[i] != s[i + 1]:
        a.append(i + 1)
        b.append(n - i - 1)

if not a:
    print(n)
    exit()
    
a1 = make_divisors(a[0])
b1 = make_divisors(b[0])

for divisor in a1[::-1]:
    for i in range(len(a)):
        if a[i] % divisor == 0 or b[i] % divisor == 0:
            pass
        else:
            break
    else:
        ans1 = divisor
        break

for divisor in b1[::-1]:
    for i in range(len(a)):
        if a[i] % divisor == 0 or b[i] % divisor == 0:
            pass
        else:
            break
    else:
        ans2 = divisor
        break
print(max(ans1, ans2))

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]:
        ans = min(ans, max(i + 1, N - i - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

S = readline().rstrip().decode()
N = len(S)

def rui(a):
    ret = [0] * (len(a) + 1)
    for i in range(len(a)):
        ret[i + 1] = ret[i] + (1 if a[i] == '1' else 0)
    return ret
r = rui(S)
print(r)

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

while ok + 1 < ng:
    med = (ng + ok) // 2
    # medで一発が必要なのは？
    le = N - med
    ri = med
    print(le,ri)
    if le >= ri:
        ok = med
    else:
        ru = r[ri] - r[le]
        if ru == 0 or ru == ri - le:
            ok = med
        else:
            ng = med

print(ok)

Submission status: Wrong Answer

Solution code:
s = input()

cnt = 0
ans = len(s)
for i, char in enumerate(s):
    if s[i] == "1" and cnt % 2 == 0:
        cnt += 1
        ans = len(s) - i
    elif s[i] == "0" and cnt % 2 == 1:
        cnt += 1
        ans = len(s) - i

print(max(ans, len(s) - ans))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

S = readline().rstrip().decode()

x = len(S)
y = len(S)
N = len(S)

for i in range(len(S)):
    if S[i] == '0':
        x = min(x , max(i,N-1-i))
    else:
        y = min(x , max(i,N-1-i))
print(max(x,y))

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

S = '9' + input()
ans = 10**5+1
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:
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

S = input()
ans = 10**5+1
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:
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

S = input()
ans = 0
cnt = 1
lastx = S[0]
scnt = []
for x in S[1:]+'9':
    if x != lastx:
        scnt.append(cnt)
        lastx = x
        cnt = 0
    cnt += 1

ttl = sum(scnt)
scnt = [0] + scnt + [0]
acc = 0
for i in range(1,len(scnt)-1):
    pl = 0
    if acc > 0:
        pl = min(acc,scnt[i+1])
    if ttl - acc - scnt[i] > 0:
        pl = max(pl,min(scnt[i-1],ttl - acc - scnt[i]))
    ans = max(ans,scnt[i] + pl)
    acc += scnt[i]
print (ans)

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

S = input()
ans = 0
cnt = 0
lastx = S[0]
scnt = []
for x in S[1:]+'9':
    if x != lastx:
        scnt.append(cnt)
        lastx = x
        cnt = 0
    cnt += 1

ttl = sum(scnt)
scnt = [0] + scnt + [0]
acc = 0
for i in range(len(scnt)-1):
    pl = 0
    if acc > 0:
        pl = min(acc,scnt[i+1])
    if ttl - acc - scnt[i] > 0:
        pl = max(pl,min(scnt[i-1],ttl - acc - scnt[i]))
    ans = max(ans,scnt[i] + pl)
    acc += scnt[i]
print (ans)

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
S += '2'
ans1 = ans2 = float('inf')
i = 0
for j in range(1, N+1):
    if S[i] != S[j]:
        if S[i] == '0':
            ans1 = min(ans1, max(i, N-j, min(j, N-i)))
        else:
            ans2 = min(ans2, max(i, N-j, min(j, N-i)))
        i = j
print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
S = input()
ans1 = ans2 = float('inf')
for i in range(len(S)):
    a = max(i, len(S)-i-1)
    if len(S) % 2 == 1 and i == len(S) // 2:
        a = i + 1
    if S[i] == '0':
        ans1 = min(ans1, a)
    else:
        ans2 = min(ans2, a)
print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
S = input()
ans1 = ans2 = float('inf')
for i in range(len(S)):
    if S[i] == '0':
        ans1 = min(ans1, max(i, len(S)-i-1))
    else:
        ans2 = min(ans2, max(i, len(S)-i-1))
print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
S = list(map(int, input()))
N = len(S)
left = 1
right = N

while left+1 < right:
	cond = 0
	mid = (left+right)//2
	f = [0] * N
	if S[0] == 1:
		f[0] = 1
	cnt = 1
	for i in range(1,N-mid+1):
		if i < mid:
			f[i] = f[i-1]
			if (S[i] + f[i]) % 2 == 1:
				f[i] += 1
			cnt += 1

		if i >= mid:
			f[i] = f[i-1] - f[i-mid]
			if (S[i] + f[i]) % 2 == 1:
				f[i] += 1
			cnt += 1
		
		if cnt >= mid:
			cond = 1
			break
	if cond == 0:
		for i in range(N-mid+1,N):
			f[i] = f[i-1] - f[i-mid]
			if (S[i] + f[i]) % 2 == 0:
				cnt += 1
			else:
				break

			if cnt >= mid:
				cond = 1
				break
	if cond:
		left = mid
	else:
		right = mid

print(left)

Submission status: Wrong Answer

Solution code:
import collections
import bisect
def main():
  S=list(map(int,list(input())))
  N=len(S)
  prev=S[0]
  tmp=1
  count=1
  for i in range(1,N):
    if prev == S[i]:
      tmp+=1
      count=max(count,tmp)
    else:
      tmp=1
      prev=S[i]
      
  l=1
  r=len(S)+1
  q=collections.deque()
  k=0
  while(l<r-1):
    mid = (l+r)//2
    flag=True
    for i,x in enumerate(S):
      id = bisect.bisect_left(q,i)
      #何個消していいか
      #1個だけ残せばいいはず
      for j in range(id-1):
        q.popleft()
        k -=1
       
      if (k + x)%2==1:
        continue
      else:
        if q and q[0]<i:
          q.popleft()
          k-=1
          continue
        elif i + (mid-1) < len(S):
          q.append(i+mid-1)
          k+=1
        else:
          flag = False
          break
    if flag:
      l=mid
    else:
      r = mid
  print(max(l,count))
      
        
main()

Submission status: Wrong Answer

Solution code:
def main():
  S=list(map(int,list(input())))
  N=len(S)
  prev=S[0]
  tmp=1
  count=1
  for i in range(1,N):
    if prev == S[i]:
      tmp+=1
      count=max(count,tmp)
    else:
      tmp=1
      prev=S[i]
  print(count)
main()

Submission status: Wrong Answer

Solution code:
def main():
  import collections
  import bisect
  S=list(map(int,list(input())))
  l=1
  r=len(S)+1
  q=collections.deque()
  k=0
  while(l<r-1):
    mid = (l+r)//2
    flag=True
    for i,x in enumerate(S):
      id = bisect.bisect_left(q,i)
      #何個消していいか
      #1個だけ残せばいいはず
      for j in range(id-1):
        q.popleft()
        k -=1
       
      if (k + x)%2==1:
        continue
      else:
        if q and q[0]<i:
          q.popleft()
          k-=1
          continue
        elif i + (mid-1) < len(S):
          q.append(i+mid-1)
          k+=1
        else:
          flag = False
          break
    if flag:
      l=mid
    else:
      r = mid
  print(l)
      
        
main()

Submission status: Wrong Answer

Solution code:
s = input()
memo = []
pre, c = s[0], 0
for si in s:
    if si != pre:
        memo.append(c)
        c = 1
    else:
        c += 1
    pre = si
memo.append(c)

if len(memo) == 1:
    print(len(s))
elif len(memo) == 2:
    print(max(memo))
else:
    ans = len(s)
    v, p = 0, 0
    for v1, v2 in zip(memo[::2], memo[1::2]):
        v = v1 + v2
        ans = min(ans, v+p)
        p = v2
    ans = min(ans, v)
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
memo = []
pre, c = s[0], 0
for si in s:
    if si != pre:
        memo.append(c)
        c = 1
    else:
        c += 1
    pre = si
memo.append(c)
if len(memo) == 1:
    print(len(s))
elif len(memo) == 2:
    print(max(memo))
else:
    ans = len(s)
    v, p = 0, 0
    for v1, v2 in zip(memo, memo[1:]):
        v = v1 + v2
        ans = min(ans, v+p)
        p = v2
    ans = min(ans, v)
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
S=input()
zero = S.count("0")
print(zero)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(map(int,list(input())))
cur = 0
cmax = 0
for i in range(1,len(S)):
    if S[i]==S[cur]:
        pass
    else:
        cmax = max(cmax,i-cur)
        cur = i
cmax = max(cmax,len(S)-cur)
j = len(S)-((len(S)+1)//2+1)
for i in range(j,len(S)):
    if S[i]!=S[j]:
        cmax = max(cmax,i)
        break
cmax = max(cmax,(len(S)+1)//2)
print(cmax)

Submission status: Wrong Answer

Solution code:
# ??
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
if S.count("0") == len(S):
	print(0)
	exit()
ans = len(S)
for i in range(len(S)-1):
	if S[i] != S[i+1]:
		ans = min(ans, max(i+1, len(S)-(i+1)))
print(ans)

Submission status: Wrong Answer

Solution code:
# ??
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
if S.count("1") == len(S):
	print(len(S))
	exit()
ans = INF
tmp = S[0]
for i in range(len(S)):
	if S[i] != tmp:
		ans = min(ans, max(i, len(S)-i))
	tmp = S[i]
print(ans)

Submission status: Wrong Answer

Solution code:
def is_ok(k):
    """00...011...1を作り、そこから00...0を作れるか調べる
    左端の1から右端の0までをXORし、(1)(2)のいずれかに収束するのを待って、判定する
    (1) 00...0<1...0>1...1 : <1...0>が解消できないならFalse
    (2) 00...01...1 : 0か1の連続長がk以上ならその区間を反転し、必要に応じて全体を反転すればよい
    """
    l, r = 0, n
    x = 0
    while True:
        while (l < r - 1) and (a[l] ^ x) == 0:
            l += 1
        while (l < r - 1) and (a[r - 1] ^ x) == 1:
            r -= 1
        len_ = r - l
        if len_ == 1:
            if (a[l] ^ x) == 0:
                l += 1
            return max(n - l, l) >= k
        elif len_ < k:
            return False
        else:
            # len_ >= k:
            x ^= 1
            l += 1


def binary_search():
    ok = 1
    ng = n + 1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


def main():
    global n, a

    s = input()

    n = len(s)
    *a, = map(int, s)

    print(binary_search())


if __name__ == '__main__':
    main()