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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

S = input()
 
lis = []
 
tmp = S[0]
cnt = 0
 
for s in S:
	if s == tmp:
		cnt += 1
	else:
		lis.append(cnt)
		tmp = s
		cnt = 1
lis.append(cnt)
 
S_len = len(S)
if len(lis) == 1:
	print(S_len)
	exit()

if len(lis) == 2:
	print(max(lis))
	exit()

tmp1 = INF
tmp2 = 0

while tmp2 < tmp1:
	tmp1 = S_len - lis[-1]
	tmp2 = lis[-1] + lis[-2]
	lis[-2] += lis[-1]
	lis.pop(-1)

print(tmp2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
ans = 0
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        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, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

S = input()

lis = []

tmp = S[0]
cnt = 0

for s in S:
	if s == tmp:
		cnt += 1
	else:
		lis.append(cnt)
		tmp = s
		cnt = 1
lis.append(cnt)

lis_acc = list(accumulate(lis))

ans = 0
for i in range(len(lis)-1):
	tmp = min(max(lis_acc[i], lis_acc[-1]-lis_acc[i]), lis[i]+lis[i+1])
	ans = max(ans, tmp)

if len(lis) == 1:
	print(lis[0])
else:
	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, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
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()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

S = input()

cnt_0 = S.count("0")
cnt_1 = S.count("1")

lis = []

tmp = S[0]
cnt = 0

for s in S:
	if s == tmp:
		cnt += 1
	else:
		lis.append(cnt)
		tmp = s
		cnt = 1
lis.append(cnt)

lis_acc = list(accumulate(lis))

ans = 0
for i in range(len(lis)-1):
	tmp = min(max(lis_acc[i], lis_acc[-1]-lis_acc[i]), lis[i]+lis[i+1])
	ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq

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

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq

s = input()
n = len(s)
prev=s[0]
ls = []
cnt=1
for i in range(1,n):
    if prev==s[i]:
        cnt+=1
    else:
        ls.append(cnt)
        prev=s[i]
        cnt=1
ls.append(cnt)
l=len(ls)
if l==1 or l==2:
    print(max(ls))
    exit()
ans = 0
#print(ls)
for i in range(l-1):
    ans =max(ans,ls[i]+ls[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    S = input() + '.'
    count = 0
    data = []
    #データ加工
    for i, s in enumerate(S[1:]):
        count += 1
        if s != S[i]:
            data.append(count)
            count = 0
    ans = 0
    l = len(data)
    #左から走査
    back = 0
    for i in range(l-1):
        K = min(back+data[i], data[i]+data[i+1])
        ans = max(ans, K)
        back += data[i]
    #右から走査
    back = 0
    for i in reversed(range(1,l)):
        K = min(back+data[i], data[i]+data[i-1])
        ans = max(ans, K)
        back += data[i]
    
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
S = list(input())
lenS = len(S)
S = S + ['.']
K = lenS
i = 1
ps = S[1]
for s in S:
    if s != ps:
        K = min(K, max(i, lenS-i))
        ps = s
    i += 1
print(K)

Submission status: Wrong Answer

Solution code:
S = list(input())
lenS = len(S)
S = S + ['.']
K = 0
i = 1
ps = S[1]
for s in S:
    if s != ps:
        K = min(K, max(i, lenS-i))
        ps = s
    i += 1
print(K)

Submission status: Wrong Answer

Solution code:
S = list(input())
lenS = len(S)
S = S + ['.']
K = 0
fro, mid, end = 0, 0, 0
ps = S[0]
for s in S:
    if s != ps:
        K = max(K,end-mid)
        ps = s
        if mid >= end-fro or lenS-mid >= end-fro:
            K = max(K, end-fro)
        fro = mid
        mid = end
    end += 1
print(K)

Submission status: Wrong Answer

Solution code:
S = list(input())
lenS = len(S)
S = S + ['.']
K = 0
fro, mid, end = 0, 0, 0
ps = S[1]
for s in S:
    if s != ps:
        K = max(K,end-mid)
        ps = s
        if mid >= end-fro or lenS-mid >= end-fro:
            K = max(K, end-fro)
        fro = mid
        mid = end
    end += 1
print(K)

Submission status: Wrong Answer

Solution code:
S = list(input())
lenS = len(S)
S += ['.']
st, fn = 0, 1
largest = 0
Largest_idx = []
ps = S[0]
for s in S[1:]:
    if s != ps:
        if fn - st > largest:
            largest = fn -st
            Largest_idx.clear()
            Largest_idx.append((st,fn))
        if fn -st == largest:
            Largest_idx.append((st,fn))
        st = fn
        ps = s
    fn += 1
Ans = [max(y-x, x, lenS-y) for x,y in Largest_idx]
print(max(Ans))

Submission status: Wrong Answer

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

key = []
count = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    key.append(count)
    count = 1
  else:
    count += 1
key.append(count)


t = len(key)
if t%2:
    ans = min(sum(key[:t//2+1]), sum(key[t//2:]))
else:
    ans = min([max(sum(key[:t//2]), sum(key[t//2:])), sum(key[:t//2+1]), sum(key[t//2-1:])])


print(ans)

Submission status: Wrong Answer

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

key = []
count = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    key.append(count)
    count = 1
  else:
    count += 1
key.append(count)


t = len(key)
if t%2:
    ans = min(sum(key[:t//2+1]), sum(key[t//2:]))
else:
    ans = max(min(sum(key[:t//2]), sum(key[t//2-1:])), min(sum(key[t//2:]), sum(key[:t//2+1])))

  
  

print(ans)

Submission status: Wrong Answer

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

key = []
count = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    key.append(count)
    count = 1
  else:
    count += 1
key.append(count)


if len(key) <= 2:
  ans = max(key)
else:
  ans = min(key[0]+key[1], key[-1]+key[-2])
  

print(ans)

Submission status: Wrong Answer

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

key = []
count = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    key.append(count)
    count = 1
  else:
    count += 1
key.append(count)


if len(key) <= 2:
  ans = max(key)
else:
  ans = 100000
  for i in range(len(key)-1):
      ans = min(ans, key[i]+key[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
s=input();n,r=len(s),0
for k in range(n-1):
  if s[k]!=s[k+1]:
    r=max(k-1,max(k+1,n-k-1))
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

S=input()

S=str(S)

int1=S.count("0")

#int2=S.count("1")

print(int1)

Submission status: Wrong Answer

Solution code:

S=input()

S=str(S)

int1=S.count("0")

int2=S.count("1")

#print(int1)

if int1>=int2:
    print(int1)
else:
    print(int2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(s.count(0))

Submission status: Wrong Answer

Solution code:
import sys

readline=sys.stdin.readline

s=readline().strip()
n=len(s)
for k in range((n+1)//2):
  if all((x==y for x,y in zip(s[k:n-k],s[k+1:]))):
    print(n-k)
    break
else:
  print((n+1)//2)

Submission status: Wrong Answer

Solution code:
import sys

readline=sys.stdin.readline

s=readline().strip()

s=s.replace('01','0 1')
s=s.replace('10','1 0')
s=s.split()

print(max(map(len,s)))

Submission status: Wrong Answer

Solution code:

import collections

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

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

print f([b for a,b in stack])

Submission status: Wrong Answer

Solution code:

import collections

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

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

print f([b for a,b in stack])

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
if S=='0'*N or S=='1'*N:
  print(N)
  exit()
cnt=0
for i in range(N-1):
  if S[i]!=S[i+1]:
    a=i+1
    b=N-a
    c=max(a,b)
    cnt=max(c,cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
#N = int(input())
S = str(input())
#X, Y = map(int, input().split())
#C = list(map(int, input().split()))
N  =len(S)
ans = 10 ** 5 + 1
for i in range(1, N):
  if S[i] != S[i - 1]:
    now = max(i, N - i)
    ans = min(ans, now)
    
print(ans)

Submission status: Wrong Answer

Solution code:
#N = int(input())
S = str(input())
#X, Y = map(int, input().split())
#C = list(map(int, input().split()))

#何個連続しているかを確認し、０１０１０１の繰り返し配列で考える
#全範囲を選択することで、010101...と101010...は同列に扱える
#0101配列として問題を解いたのち、各々の連続しているながさを考慮して、本問の答えに至る
conti = []
now = 1
for i in range(1, len(S)):
  if S[i] == S[i - 1]:
    now += 1
  else:
    conti.append(now)
    now = 1
    
conti.append(now)

#print(conti)
#01配列のながさ
nn = len(conti)
#01配列として問題を解いたときの答え
ss = int((nn + 1) / 2)

#累積和
#最初を0にするため、nn + 1
ruiseki = [0] * (nn + 1)
for i in range(nn):
  ruiseki[i + 1] = ruiseki[i] + conti[i]
#print(ruiseki)  

ans = 10 ** 5 + 1#2番目に小さい
pesudo = 10 ** 5 + 1#一番小さい
#一番小さい区間一つだけは選択せずに避けることができる
for i in range(nn - ss + 1):
  now = ruiseki[i + ss] - ruiseki[i]
  if now < pesudo:
    ans = pesudo
    pesudo = now 
  elif now < ans:
    ans = now
  #print(ans, pesudo)  
  
#print(nn, ss)
if nn % 2 == 0:
  print(ans)
else:
  print(pesudo)

Submission status: Wrong Answer

Solution code:
#N = int(input())
S = str(input())
#X, Y = map(int, input().split())
#C = list(map(int, input().split()))

#何個連続しているかを確認し、０１０１０１の繰り返し配列で考える
#全範囲を選択することで、010101...と101010...は同列に扱える
#0101配列として問題を解いたのち、各々の連続しているながさを考慮して、本問の答えに至る
conti = []
now = 1
for i in range(1, len(S)):
  if S[i] == S[i - 1]:
    now += 1
  else:
    conti.append(now)
    now = 1
    
conti.append(now)

#print(conti)
#01配列のながさ
nn = len(conti)
#01配列として問題を解いたときの答え
ss = int((nn + 1) / 2)

#累積和
#最初を0にするため、nn + 1
ruiseki = [0] * (nn + 1)
for i in range(nn):
  ruiseki[i + 1] = ruiseki[i] + conti[i]
#print(ruiseki)  

ans = 10 ** 5 + 1#2番目に小さい
pesudo = 10 ** 5 + 1#一番小さい
#一番小さい区間一つだけは選択せずに避けることができる
for i in range(nn - ss + 1):
  now = ruiseki[i + ss] - ruiseki[i]
  if now < pesudo:
    ans = pesudo
    pesudo = now 
  elif now < ans:
    ans = now
  #print(ans, pesudo)  
  
#print(nn, ss)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
print(S.count('0'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
arr = []
now = S[0]
cnt = 1
for s in S[1:]:
    if s == now:
        cnt += 1
    else:
        arr.append(cnt)
        cnt = 1
        now = s
arr.append(cnt)
if len(arr) <= 2:
    print(max(arr))
    exit()
L = len(arr)
ans = 10**18
for i in range(L):
    if i%2 == 0:
        n = arr[i]
        if i > 0: n += arr[i-1]
        if i < L-1: n += arr[i+1]
        ans = min(ans, n)
print(max(ans, max(arr)))

Submission status: Wrong Answer

Solution code:
S = input()
arr = []
now = S[0]
cnt = 1
for s in S[1:]:
    if s == now:
        cnt += 1
    else:
        arr.append(cnt)
        cnt = 1
        now = s
arr.append(cnt)
if len(arr) <= 2:
    print(max(arr))
    exit()
L = len(arr)
ans = 10**18
for i in range(L):
    if i%2 == 0:
        n = arr[i]
        if i > 0: n += arr[i-1]
        if i < L-1: n += arr[i+1]
        ans = min(ans, n)
print(ans)

Submission status: Wrong Answer

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    

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

    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
cs=[]
cnt=1
pre=s[0]
for si in s[1:]:
  if si==pre:
    cnt+=1
  else:
    cs.append(cnt)
    pre=si
    cnt=1
cs.append(cnt)
#print(cs)
csl=[0]
tmp=0
for i in range(len(cs)):
  tmp+=cs[i]
  csl.append(tmp)
csr=[0]
tmp=0
for i in range(len(cs)-1,-1,-1):
  tmp+=cs[i]
  csr.append(tmp)
ans=0
for i in range(len(cs)):
  # 左右両方まとめる
  if i>0 and i<len(cs)-1:
    k=cs[i-1]+cs[i]+cs[i+1]
    if k<=csl[i] and k<=csr[len(cs)-i-1]:
      ans=max(ans,k)
  # 左をまとめる
  if i>0:
    k=cs[i-1]+cs[i]
    if k<=csl[i]:
      ans=max(ans,k)
  # 右をまとめる
  if i<len(cs)-1:
    k=cs[i]+cs[i+1]
    if k<=k<=csr[len(cs)-i-1]:
      ans=max(ans,k)
  # まとめない
  ans=max(ans,cs[i])
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

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

print(a)

Submission status: Wrong Answer

Solution code:
S = input()
n = len(S)    
K = 0
for k in range(n-1):
    if S[k] != S[k+1]:
        K = max(K, k, n-k-1)
print(K)

Submission status: Wrong Answer

Solution code:
S = list(input())

def check(x):
    print(S[len(S)-x:x])
    for y in S[len(S)-x:x]:
        if y != S[len(S)-x]: break
    else:
        return True
    return False

def bisect(l,r):
    if r - l == 1: return l
    mid = (l+r) // 2
    if check(mid) == False:
        return bisect(l,mid)
    else:
        return bisect(mid,r)
print(bisect(1,len(S)+1))

Submission status: Wrong Answer

Solution code:
S = list(input())

def check(x):
    #print(S[len(S)-x:x])
    for y in S[len(S)-x:x]:
        if y != S[len(S)-x]: break
    else:
            return True
    return False

def bisect(l,r):
    if r - l == 1: return l
    mid = (l+r) // 2
    if check(mid) == False:
        return bisect(l,mid)
    else:
        return bisect(mid,r)
print(bisect(0,len(S)))

Submission status: Wrong Answer

Solution code:
def rle(s):
    # ex. '01100011110' -> [1 2 3 4 1]
    before_c = s[0]
    ret = list()
    cnt = 0
    for c in s:
        if before_c == c:
            cnt += 1
        else:
            ret.append(cnt)
            before_c = c
            cnt = 1
    if cnt > 0:
        ret.append(cnt)
    return ret


def main():
    S = input()
    seq_cnt = rle(S)
    if len(seq_cnt) == 1:
        print(seq_cnt[0])
        return
    if len(seq_cnt) == 2:
        print(max(seq_cnt))
        return
    # cumsum
    cumsum_seq_cnt = [0 for _ in range(len(seq_cnt))]
    cumsum_seq_cnt[0] = seq_cnt[0]
    for i in range(1, len(seq_cnt)):
        cumsum_seq_cnt[i] = cumsum_seq_cnt[i-1] + seq_cnt[i]
    # search
    max_k = 1
    for i in range(len(seq_cnt) - 1):
        k = min([
            seq_cnt[i] + seq_cnt[i+1],
            max([
                cumsum_seq_cnt[i],
                len(S) - cumsum_seq_cnt[i]
            ])
        ])
        max_k = max([max_k, k])
    print(max_k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def rle(s):
    # ex. '01100011110' -> [1 2 3 4 1]
    before_c = s[0]
    ret = list()
    cnt = 0
    for c in s:
        if before_c == c:
            cnt += 1
        else:
            ret.append(cnt)
            before_c = c
            cnt = 1
    if cnt > 0:
        ret.append(cnt)
    return ret


def main():
    S = input()
    seq_cnt = rle(S)
    if len(seq_cnt) == 1:
        print(seq_cnt[0])
        return
    if len(seq_cnt) == 2:
        print(max(seq_cnt))
        return
    # cumsum
    cumsum_seq_cnt = [0 for _ in range(len(seq_cnt))]
    cumsum_seq_cnt[0] = seq_cnt[0]
    for i in range(1, len(seq_cnt)):
        cumsum_seq_cnt[i] = cumsum_seq_cnt[i-1] + seq_cnt[i]
    # search
    max_k = 1
    for i in range(len(seq_cnt) - 1):
        k = seq_cnt[i] + seq_cnt[i+1]
        if k <= max([cumsum_seq_cnt[i], len(S) - cumsum_seq_cnt[i]]):
            max_k = max([max_k, k])
    print(max_k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def rle(s):
    # ex. '01100011110' -> [1 2 3 4 1]
    before_c = s[0]
    ret = list()
    cnt = 0
    for c in s:
        if before_c == c:
            cnt += 1
        else:
            ret.append(cnt)
            before_c = c
            cnt = 1
    if cnt > 0:
        ret.append(cnt)
    return ret


def main():
    S = input()
    seq_cnt = rle(S)
    if len(seq_cnt) == 1:
        print(seq_cnt[0])
        return
    if len(seq_cnt) == 2:
        print(max(seq_cnt))
        return
    # search
    max_k = 1
    for i in range(len(seq_cnt) - 1):
        k = seq_cnt[i] + seq_cnt[i+1]
        if k <= max([sum(seq_cnt[:(i+1)]), sum(seq_cnt[(i+1):])]):
            max_k = max([max_k, k])
    print(max_k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    S=list(map(int,list(input())))
    N=len(S)
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(mid):
        T=S[:mid]
        a=T[0]
        for x in T:
            if x!=a:
                U=S[-mid:]
                b=U[0]
                for x in U:
                    if x!=b:
                        return False
                else:
                    return True
        else:
            return True
        
    print(nibutan(-(-N//2),N+1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
from itertools import *
if len(s) == 1:
    print(1)
    exit()
if len(s) == 2:
    if s[0] != s[1]:
        print(1)
    else:
        print(2)
    exit()
print(max([len(s) // 2 + (len(s) % 2 == 1), max(len(list(v)) for k, v in groupby(s))]))

Submission status: Wrong Answer

Solution code:
s = input()
from itertools import *
if len(s) == 1:
    print(1)
    exit()
if len(s) == 2:
    if s[0] != s[1]:
        print(1)
    else:
        print(2)
    exit()
print(max([2, max(len(list(v)) for k, v in groupby(s))]))

Submission status: Wrong Answer

Solution code:
s = input()
from itertools import *
print(max([2, max(len(list(v)) for k, v in groupby(s))]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
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))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = 0
r = n//2 + 1

while r - l > 1:
    m = l + (r-l)//2
    d = n//2 - m
    print(s[d:n-d])
    if s[d:n-d].count("0") == 0 or s[d:n-d].count("1") == 0:
        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:
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:n-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)