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: Accepted

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

if N % 2 == 0:
    n = int(N // 2)
    K = n
    i = 0
    while i < n:
        if S[n - 1 - i] == S[n + i]:
            i += 1
        else:
            break

    print(K + i)
else:
    n = int((N - 1) // 2)
    if N == 1:
        print(1)

    else:
        K = n + 1
        i = 0
        if S[n] == S[n + 1]:
            while i < n:
                if S[n - i - 1] == S[n + i + 1]:
                    i += 1
                else:
                    break
        print(K + i)

Submission status: Accepted

Solution code:
s = input().strip()

ans = len(s)
for i, (prevs, _s) in enumerate(zip(s, s[1:])):
  if prevs != _s:
    ans = min(ans, max(i+1, len(s)-i-1))
print(ans)

Submission status: Accepted

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

s = input()

K = float('inf')
if all(c == '0' for c in s):
    K = len(s)
elif all(c == '1' for c in s):
    K = len(s)
else:
    for k in range(1, len(s)):
        if s[k] != s[k-1]:
            K = min(K, max(k, len(s)-k))
        else:
            continue

print(K)

Submission status: Accepted

Solution code:
S=input()

l=len(S)

if l%2==0:
    count=l//2
    a=S[l//2-1]
    for i in range(l//2):
        if S[l//2-1-i]==a and S[l//2+i]==a:
            count+=1
        else:
            break
    print(count)
else:
    count=l//2+1
    a=S[l//2]
    for i in range(l//2):
        if S[l//2-1-i]==a and S[l//2+1+i]==a:

            count+=1
        else:
            break
    print(count)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()
size = len(S)
if len(S) % 2 == 0:
    ans = size // 2
    base = S[size // 2]
    for i in range(size // 2):
        if S[size // 2 - 1 - i] == S[size // 2 + i] == base:
            ans += 1
        else:
            break
    print(ans)
else:
    ans = size // 2 + 1
    base = S[size // 2]
    for i in range(size // 2):
        if S[size // 2 - 1 - i] == S[size // 2 + 1 + i] == base:
            ans += 1
        else:
            break
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

length = len(s)
i = 0
while i < len(s) - 1:
    if s[i] != s[i+1]:
        length = min(length, max(i+1, len(s) - i - 1))
    i += 1
print(length)

Submission status: Accepted

Solution code:
s=input()
N=len(s)
ans=N//2
for i in range(N//2+1,N):
  if s[N-i:i]=="0"*(2*i-N) or s[N-i:i]=="1"*(2*i-N):
    ans=i
if s=="0"*N or s=="1"*N:
  ans=N
print(ans)

Submission status: Accepted

Solution code:
def main():
    buf = input()
    S = buf
    K = len(S) // 2
    center_char = S[K]
    while K < len(S):
        if S[K] == center_char and S[-K - 1] == center_char:
            K += 1
        else:
            break
    print(K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

S = input()
l=len(S)
if l%2==0:
    count=0
    s=S[int(l/2)]
    for i in range(int(l/2)):
        if S[int(l/2)-1-i]!=s or S[int(l/2)+i]!=s:
            break
        count+=1
    print(int(l/2)+count)
else:
    s=S[int(l/2)]
    count=0
    for i in range(int(l/2)):
        if S[int(l/2)-1-i]!=s or S[int(l/2)+1+i]!=s:
            break
        count+=1
    print(int(l/2)+1+count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = list(input())
n = len(s)
res = 10**6

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

if res==10**6:
    res = n
print(res)

Submission status: Accepted

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+1,n-i-1))

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans = N
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: Accepted

Solution code:

import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    S = input_raw[0]
    count = 0
    N = len(S)
    if len(S) % 2 == 0:
        for i  in range(0, N/2):
            if S[N/2] == S[N/2 - i - 1]  and S[N/2] == S[N/2 + i]:
                count += 2
            else:
                break

    else:
        count += 1
        for i in range(1, N/2 + 1):
            if S[N/2] == S[N/2 - i] and S[N/2] == S[N/2 + i]:
                count += 2
            else:
                break

    K = N -(N - count)/2

    print K

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

S = raw_input()

mid = len(S) / 2
c = S[mid]
ans = mid

for i in range((len(S) + 1) / 2):
    pos1 = len(S) / 2 + i
    pos2 = (len(S) - 1) / 2 - i
    if c == S[pos1] == S[pos2]:
        ans += 1
    else:
        break

print ans

Submission status: Accepted

Solution code:
S=list(input())

K=(len(S)+1)//2

if len(S)%2==0:
  mark=S[len(S)//2]
  if mark!=S[len(S)//2-1]:
    print(K)
    exit()
  count=1
  while(0<len(S)-K-count):
    if mark!=S[len(S)//2-1-count] or mark!=S[len(S)//2+count]:
      print(K+count)
      exit()
    count+=1
  print(K+count)
else:
  mark=S[len(S)//2]
  count=0
  while(0<len(S)-K-count):
    if mark!=S[len(S)//2-1-count] or mark!=S[len(S)//2+1+count]:
      print(K+count)
      exit()
    count+=1
  print(K+count)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import *

S = input()
N = len(S)

def solvable(k):
  imos = [0] * (N+1)
  ops = [0] * (N+1)
  for i in range(N-k+1):
    ops[i] = ops[i-1] + imos[i]
    if int(S[i] == '1') ^ (ops[i] & 1):
      imos[i] += 1
      imos[i+k] -= 1
      ops[i] += 1
  ops = list(accumulate(imos))[:-1]
  return not any(int(S[i] == '1') ^ (ops[i] & 1) for i in range(k))

l = 1
r = N+1
while r - l > 1:
  m = (l + r) // 2
  if solvable(m):
    l = m
  else:
    r = m
print(l)

Submission status: Accepted

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

def main():
    s = input()
    n = len(s)
    chs = changes(s, n)

    res = n
    for c in chs:
        di = max(c, n - c)
        res = min(res, di)

    print(res)

def changes(s, n):
    res = []
    for i in range(1, n):
        if s[i - 1] != s[i]:
            res.append(i)
    return res

main()

Submission status: Accepted

Solution code:
import sys
S = [1 if i =='1' else 0 for i in input()]
l=len(S)
if l%2==1:
    t=l//2
    a = S[t]
    for i in range(1,t+1):
        if S[t-i]!=a or S[t+i]!=a:
            print(t+i)
            sys.exit()
    print(l)
    sys.exit()
if l%2==0:
    t=l//2
    a = S[t-1]
    b=S[t]
    if a!=b:
        print(t)
        sys.exit()
    for i in range(1,t):
        if S[t-1-i]!=a or S[t+i]!=a:
            print(t+i)
            sys.exit()
    print(l)
    sys.exit()

Submission status: Accepted

Solution code:
s = input()
s = list(map(int, list(s)))
 
now = s[0]
cnt = 0
stack = []
for e in s:
    if now == e:
        cnt += 1
    else:
        stack.append(cnt)
        cnt = 1
        now = e
stack.append(cnt)
 
# print(stack)
 
l = len(stack)
ans = int(1e18)
if l == 1:
    ans = len(s)
else:
    cnt = 0
    for i in range(l):
        cnt += stack[i]
        ans = min(ans, max(cnt, len(s)-cnt))
 
print(ans)

Submission status: Accepted

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

if len(set(S)) == 1:
	print(len(S))
else:
	ans = 1000000
	for i in range(n-1):
		if S[i] != S[i+1]:
			m = max(n - i - 1, i + 1)
			if m < ans:
				ans = m

	print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    s = f.read_str()
    n = len(s)
    if n % 2 == 0:
        if s[n/2-1] != s[n/2]: return n/2
        c = s[n/2]
        ans = n/2
        for i in xrange(n/2-1, -1, -1):
            if s[i] != c or s[n-i-1] != c: break
            ans += 1
        return ans
    else:
        c = s[n/2]
        ans = n/2 + 1
        for i in xrange(n/2-1, -1, -1):
            if s[i] != c or s[n-i-1] != c: break
            ans += 1
        return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

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

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

ans = N//2
l = r = N//2
if N%2 == 0: l -= 1

inside = None
while l >= 0:
    if not inside:
        if N%2:
            if S[l] == 1:
                print(N//2 + 1)
                exit()
        else:
            if S[l] != S[r]:
                print(N//2)
                exit()
        inside = S[l]
        continue
    if S[l] != inside or S[r] != inside:
        break
    inside = S[l]
    l -= 1
    r += 1
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s= raw_input()
def solve():
    prev = s[0]
    ans = len(s)
    for i in range(0,len(s)):
        if prev != s[i]:
            ans = min(ans,max(i,len(s)-i))
            prev = s[i]
    print ans
solve()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
for k in range((N+1)//2, N):
    if S[k-1] != S[k] or S[-k] != S[-k-1]:
        print(k)
        break
else:
    print(N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
for k in range((len(S)+1)//2-1, len(S)-1):
    if S[k] != S[k+1] or S[-k-1] != S[-k-2]:
        print(k+1)
        break
else:
    print(len(S))

Submission status: Accepted

Solution code:
S = input()

i = len(S)//2
j = i - 1 + len(S)%2
v = S[i]

while j >= 0 and S[i] == S[j] == v :
    i += 1
    j -= 1

res = len(S) - j - 1
print(res)

Submission status: Accepted

Solution code:

def ok(S, K):
    s = ''
    for i in range(len(S)):
        if i < K and i >= len(S) - K:
            s += S[i]

    if s == '':
        return True
    return all([c == s[0] for c in s])


S = input()
lb = 1
ub = len(S) + 1
while ub - lb > 1:
    mid = (ub + lb) // 2
    if ok(S, mid):
        lb = mid
    else:
        ub = mid

print(lb)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
n = len(S)
L = list(map(int, list(S)))
D = []
res = 0
for k in range(n-1):
    if L[k] != L[k+1]:
        D.append(max(k+1, n-k-1))

if len(D):
    print(min(D))
else:
    print(n)

Submission status: Accepted

Solution code:
from collections import Counter

item = str(input())
longest = [0,0]
shortest = [len(item),len(item)]
current = 1

def exchange(item):
    for i in range(1, len(item)):
        if item[i-1] != item[i]:
            return max(exchange(item[0:i]), exchange(item[i:]))
    return len(item)

N = len(item)
T = N
for k in range(1, N):
    if item[k-1] != item[k]:
        tmp = max(k, N-(k))
        if T >= tmp:
            T = tmp

print(T)

Submission status: Accepted

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

wk=length
bk=length
for i, s in enumerate(S):
    cost=max(i, length-(i+1))
    if s == "0":
        wk = min(wk, cost)
    else:
        bk = min(bk, cost)
print(max(wk, bk))

Submission status: Accepted

Solution code:
s, o = raw_input(), float('inf')
for i in xrange(len(s) - 1):
    if s[i] != s[i + 1]:
        o = min(o, max(i + 1, len(s) - i - 1))
print o if o != float('inf') else len(s)

Submission status: Accepted

Solution code:
inp = input()
nStr = len(inp)
ret = nStr//2


if(inp[nStr//2] == "1"):
    for i in reversed(range((nStr-1)//2 + 1)):
        if((inp[i] == inp[nStr-i-1]) and (inp[i] == "1")):
            ret += 1
        else:
            break
    print(ret)

else:            
    for i in reversed(range((nStr-1)//2 + 1)):
        if((inp[i] == inp[nStr-i-1]) and (inp[i] == "0")):
            ret += 1
        else:
            break
    print(ret)

Submission status: Accepted

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

S = input()
n = len(S)
T = []

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

Submission status: Accepted

Solution code:
s=raw_input()
k=len(s)/2+1
lef=(len(s)-1)/2
ch=s[lef]
rig=(len(s))/2
while 0<=lef and rig<len(s):
    if s[lef]==s[rig] and ch==s[lef]:
        k+=1
        lef-=1
        rig+=1
    else:
        k-=1
        break
print(k-(lef==-1))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    l = len(s)
    a = [c == '1' for c in s]
    r = l//2 + l%2
    b = l//2 - 1
    c = l//2 + l%2
    for i in range(b+1):
        if a[b-i] != a[b-i+1] or a[c+i] != a[c+i-1]:
            break
        r += 1

    return r



print(main())

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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


if N % 2 == 1:
    mid = N // 2
    K = N
    for i in range(mid):
        if S[mid] != S[mid + i + 1]:
            K = min(K, N - mid + i)
            break
    for i in range(mid):
        if S[mid] != S[mid - i - 1]:
            K = min(K, N - mid + i)
            break

if N % 2 == 0:
    mid_right = N // 2
    mid_left = N // 2 - 1
    K = N
    for i in range(N // 2):
        if S[mid_left] != S[mid_left + i + 1]:
            K = min(K, N//2 + i)
            break
    for i in range(N // 2):
        if S[mid_right] != S[mid_right - i - 1]:
            K = min(K, N//2 + i)


print(K)

Submission status: Accepted

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

ans = n // 2
for i in range(n // 2, n):
    if s[i] == s[n - 1 - i] == s[n // 2]:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
s=input()
cnt=len(s)//2
i=0
if len(s)%2:
    while cnt+i<len(s) and s[cnt-i]==s[cnt+i]==s[cnt]:
        i+=1
else:
    while cnt+i<len(s) and s[cnt-i-1]==s[cnt+i]==s[cnt]:
        i+=1
print(cnt+i)

Submission status: Accepted

Solution code:
S=raw_input()
n=len(S)
S=S+"0"
ans=n
for i in xrange(n) :
    if S[i]!=S[i+1] :
        ans=min(ans,max(i+1,n-1-i))
print ans

Submission status: Accepted

Solution code:
S = input()


def kaisetsu(S):
    n = len(S)
    K = n
    for i in range(n - 1):
        if S[i] != S[i + 1]:
            k = max(i + 1, n - i - 1)
            K = min(K, k)
    return K
 

print(kaisetsu(S))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
c = 0
p = n//2
for i in range(n//2,n):
  if s[p]!=s[i] or s[p]!=s[n-i-1]:break
  c += 1
print(n//2+c)

Submission status: Accepted

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

def solve():
    s = input()
    n = len(s)

    ans = len(s)
    current_number = s[0]
    for k, c in enumerate(s):
        if c != current_number:
            ans = min(ans, max(k, n - k))
            current_number = c
    print(ans)

if __name__=="__main__":
    solve()

Submission status: Accepted

Solution code:
import numpy as np 
s = input()
fis = s[0]
n = len(s)
k = n
temp = s[0]
for i in range(n):
    if temp!=s[i]:
        temp = s[i]
        k = np.min((k, np.max( (i, n-i) ) ))
print("{}".format(int(k)))

Submission status: Accepted

Solution code:
'''input
010
'''

def list_input():
    return list(map(int,input().split()))
def map_input():
    return map(int,input().split())
def map_string():
    return input().split()
    
s = input()
n = len(s)
l = (n-1)//2
r = n//2
ans = n//2
cur = s[l]
while l >= 0:
	if s[l] == s[r] and s[l] == cur:
		ans += 1
		l -= 1
		r += 1
	else: break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

m = N//2
if N%2 == 0:
    if S[m] != S[m-1]:
        print(m)
        exit()
    ans = m+1
    for i in range(1,m):
        if S[m] == S[m+i] == S[m-1-i]:
            ans += 1
        else:
            break
else:
    ans = m+1
    for i in range(1,m+1):
        if S[m] == S[m+i] == S[m-i]:
            ans += 1
        else:
            break
print(ans)

Submission status: Accepted

Solution code:
s = input()

l = len(s)

t = l

for i,x in enumerate(s):
    if i == 0:
        pass
    else:
        if x != s[i-1]:
            a = max(i,l-i)
            t = min(t,a)

print(t)

Submission status: Accepted

Solution code:
s = input()

cflag=[]
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    cflag+=[i+1]
  
ans = len(s)
for flag in cflag:
  ans = min(ans,max(flag,len(s)-flag) )
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

ans = min(1, len(s) // 2)
prev = -1
for i in range(ans, len(s) + 1):
    m_b = len(s) - i
    m_e = i
    is_ok = True
    if m_b < m_e:
        m_e = m_e - 1
        if prev == -1:
            prev = s[m_b]
        if prev != s[m_b] or prev != s[m_e]:
            is_ok = False
    if is_ok:
        ans = i
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
# 無限回試行できる時、Kの最小値を最大化する問題
s = input()
now = s[0]
cnt = 1
use = []
for i in range(1,len(s)):
    if now == s[i]:
        cnt += 1
    else:
        use.append(cnt)
        cnt = 1
        now = s[i]
use.append(cnt)

min_prob = len(s)
sum_s = sum(use)
def ketsugou(l):
    global min_prob
    global sum_s
    #一番小さいやつをくっつけていく
    m = l.index(min(l))
    if m == 0 or m == len(l) - 1:
        s1 = l[m]
        s2 = sum_s - l[m]
        min_prob = min(min_prob, max(s1, s2))
        if m == 0:
            l = l[1:]
            l[0] += s1
        else:
            l.pop()
            l[-1] += s1
    else:
        s1 = sum(l[:m])
        s2 = s1 + l[m]
        s3 = sum_s - s1
        s4 = sum_s - s2
        min_prob = min(min_prob, max(s1, s2,s3,s4))
        if l[m - 1] < l[m + 1]:
            l[m - 1] += l[m]
        else:
            l[m + 1] += l[m]
        l.pop(m)
#while(len(use) > 1):
#    ketsugou(use)
sum_ss = 0
for i in range(len(use)):
    sum_ss += use[i]
    min_prob = min(min_prob, max(sum_s - sum_ss, sum_ss))

print(min_prob)

Submission status: Accepted

Solution code:
Ss = input()

Ns = []
prev = Ss[0]
num = 0
for S in Ss:
    if S != prev:
        Ns += [num]
        num = 1
    else:
        num += 1
    prev = S

Ns += [num]

sumN = 0
restN = sum(Ns)
ans = float('inf')
for N in Ns:
    sumN += N
    restN -= N
    ans = min(ans, max(sumN, restN))

print(ans)

Submission status: Accepted

Solution code:
S = raw_input()
A = [0]
for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    A += [i+1]
A += [len(S)]
B = [A[i+1]-A[i] for i in range(len(A)-1)]

s = sum(B)
ans = 0
l = 0
for b in B:
  ans = max(ans, min(l+b, s-l))
  l += b
print ans

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
lenS = len(S)
count0 = S.count(0)
if count0 == 0 or count0 == len(S):
	print(lenS)
	exit()

if lenS % 2 == 1:
	center = int(lenS/2)
	K = 1
	while K < center:
		if S[center-K] == S[center] and S[center + K] == S[center]:
			K += 1
			continue
		else:
			break
	K = center + K
else:
	center = int(lenS/2)
	K = 1
	while K < center:
		if S[center-K] == S[center+K-1] and S[center-K] == S[center]:
			K += 1
			continue
		else:
			break
	K = center + K - 1

print(K)
"""
def reverse(A, l, n):
	for x in range(n):
		A[l+x] = 1 - A[l+x]

L = int(lenS/2)
while L < R:
	K = int((L+R+1)/2)
	test = [i for i in S]
	for i in range(lenS - K + 1):
		if test[i] == 1:
			reverse(test, i, K)
	flag = True
	for i in range(K):
		if test[i] == 1:
			flag = False
			break
	if flag:
		L = K
	else:
		R = K - 1
		S = test
print(L)
"""

Submission status: Accepted

Solution code:
from collections import deque
arr = deque()
prev = None
num = 0
for c in input():
  if prev is not None and c != prev:
    arr.append(num)
    num = 0
  prev = c
  num += 1
arr.append(num)

while len(arr) > 2:
  if arr[0] > arr[-1]:
    v = arr.pop()
    v += arr.pop()
    arr.append(v)
  else:
    v = arr.popleft()
    v += arr.popleft()
    arr.appendleft(v)

print(max(arr))

Submission status: Accepted

Solution code:
s = input()

if len(s) % 2 == 0:
    c = 0
    m = len(s) // 2 - 1
    x = s[m]
    while c <= m and x == s[m-c] and x == s[m+1+c]:
        c += 1
    print(len(s) // 2 + c)
else:
    c = 0
    m = len(s) // 2
    x = s[m]
    while c < m and x == s[m-1-c] and x == s[m+1+c]:
        c += 1
    print(len(s) // 2 + c + 1)

Submission status: Accepted

Solution code:
S = input()
cnt = 0

i = len(S)//2
j = i - 1 + len(S)%2 
v = S[i]

while j >= 0 and S[i] == S[j] == v:
  i += 1
  j -= 1

res = len(S) - j - 1
print(res)

Submission status: Accepted

Solution code:
def solve(s):
    n = len(s)

    if n == 1:
        return 1
    if n == 2:
        return 2 if s[0] == s[1] else 1

    ci = n // 2
    c = s[ci]
    if n & 1:
        for di in range(1, ci + 1):
            if c == s[ci - di] == s[ci + di]:
                pass
            else:
                return ci + di
        return n
    if c != s[ci - 1]:
        return ci
    for di in range(1, ci):
        if c == s[ci - di - 1] == s[ci + di]:
            pass
        else:
            return ci + di
    return n


print(solve(input()))

Submission status: Accepted

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

ansone, anszero = n, n
for i, c in enumerate(s):
    ld, rd = i, n - i - 1
    if c == '1':
        ansone = min(ansone, max(ld, rd))
    else:
        anszero = min(anszero, max(ld, rd))
print(max(ansone, anszero))

Submission status: Runtime Error

Solution code:
mod = 10**9+7
import sys
import math
from collections import Counter, defaultdict, deque
import copy

# from itertools import product, permutations, combinations, combinations_with_replacement
# from itertools import accumulate
# from operator import itemgetter
# from bisect import bisect_bound_list,bisect
# from heapq import heappop,heappush
# from math import ceil,floor
# from copy import deepcopy
# from heapq import heappop,heappush,heapify
# import heapq


# def combinations(n, r):
# 	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# def gcd(a, b):
# 	if b == 0:
# 		return a
# 	else:
# 		return gcd(b, a%b)
 
# def lcm(a, b):
# 	return a // gcd(a, b) * b

# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

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

Submission status: Runtime Error

Solution code:
mod = 10**9+7
import sys
import math
from collections import Counter, defaultdict, deque
import copy

# from itertools import product, permutations, combinations, combinations_with_replacement
# from itertools import accumulate
# from operator import itemgetter
# from bisect import bisect_bound_list,bisect
# from heapq import heappop,heappush
# from math import ceil,floor
# from copy import deepcopy
# from heapq import heappop,heappush,heapify
# import heapq


# def combinations(n, r):
# 	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# def gcd(a, b):
# 	if b == 0:
# 		return a
# 	else:
# 		return gcd(b, a%b)
 
# def lcm(a, b):
# 	return a // gcd(a, b) * b

# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = Counter(l)

# d = defaultdict(int)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

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

Submission status: Runtime Error

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

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: Runtime Error

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

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))
if ans == 0: ans = len(S)

print (ans)