Problem:


Score : 500 points

Problem Statement

You are given a string S consisting of 0 and 1.
Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.

Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.

Constraints

1\leq |S|\leq 10^5

S_i(1\leq i\leq N) is either 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.

Sample Input 1

010

Sample Output 1

2

We can turn all the characters of S into 0 by the following operations:

Perform the operation on the segment S[1,3] with length 3. S is now 101.

Perform the operation on the segment S[1,2] with length 2. S is now 011.

Perform the operation on the segment S[2,3] with length 2. S is now 000.

Sample Input 2

100000000

Sample Output 2

8

Sample Input 3

00001111

Sample Output 3

4



Sample input:
010


Sample output:
2

Submission status: Wrong Answer

Solution code:
s=input()
count=0
maxcount=0
if len(s)==1:
  print(1)
else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count=count+1
        else:
            maxcount=max(maxcount,count+1)
            count=0
        maxcount=max(maxcount,count+1)
    if 2*maxcount<len(s):
#    print(max(2,maxcount))
        print(maxcount+1)
    else:
        print(maxcount)

Submission status: Wrong Answer

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

if p > len(S) - p:
    print(p)
else:
    print(len(S)-p)

Submission status: Wrong Answer

Solution code:
s = input()
c = s.count('0')
print(c)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(S)
ans = S.count("0")
if ans > N:
    ans = N
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
from collections import Counter
print(Counter(S)['0'])

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
for item in s:
    if item == '0':
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1

while len(res) >1:
    resu = min(resu,max(res[0],sum(res[1:])))
    x = res.pop(1)
    res[0]  = res[0]+x    
    
print(resu)

Submission status: Time Limit Exceeded

Solution code:
s = input()

sl = list(s)
sl.append("2")

n = len(sl)
res=[]

temp =1
for i  in range(n-1):
    if sl[i+1] == sl[i]:
        temp +=1
    else:
        res.append(temp)
        temp = 1

resu = n-1

while len(res) >1:
    if res[0] > sum(res[1:]):
        resu = min(resu,res[0])
        x = res.pop(1)
        res[0] = res[0]+x
    else:
        resu = min(resu,sum(res[1:]))
        x = res.pop(1)
        res[0] =res[0]+x

print(resu)

Submission status: Time Limit Exceeded

Solution code:
# D
s = input()
length = len(s)
k = length
mid = length//2
max_k = None

while k>mid:
    overlap = s[length-k:k]
    pure = len(set(overlap)) == 1
    if pure:
        max_k = k
        print(max_k)
        break
    k -= 1

if not max_k:
    print(mid)

Submission status: Time Limit Exceeded

Solution code:
s = input()
length = len(s)
k = length
mid = length//2

while k>mid:
    overlap = s[length-k:k]
    pure = len(set(list(overlap))) == 1
    if pure:
        print(k)
        exit()
    k -= 1

print(mid)

Submission status: Time Limit Exceeded

Solution code:
w=input()
a=[(i+1)*(j=="0") for i,j in enumerate(w)]
b=[(i+1)*(j=="1") for i,j in enumerate(w)]
l=len(w)
w=list(w)
for t in range(1,l+1):
	m=min(max(a[:t]),max(b[:t]))
	if l-m<t:
		print(t-1)
		exit()
print(l)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)
if N % 2 == 0:
    M = N // 2
    ans = M
    for i in range(M):
        T = S[i:N - i]
        if len(set(T)) == 1:
            ans = N - i
            break
else:
    M = N // 2 + 1
    ans = M
    for i in range(M):
        T = S[i:N - i]
        if len(set(T)) == 1:
            ans = N - i
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S=raw_input()

L=len(S)

ans=L/2
for r in range(L/2,L):
	C=Counter(S[L-r-1:r+1])
	if len(C)==1:
		ans=r+1

print ans

Submission status: Time Limit Exceeded

Solution code:
s = [int(x) for x in input()]

for k in range(len(s)//2 + 1, len(s)+1):
    if (not all(s[len(s)-k:k])) and any(s[len(s)-k:k]):
        print(k - 1)
        break
else:
    print(len(s))

Submission status: Time Limit Exceeded

Solution code:
a=list(map(int,list(input())))
count=len(a)
while sum(a)!=0 and sum(a)!=len(a):
    a.pop()
    a.pop(0)
    count-=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 1
maxc = 1
maxp = 0
smax = 10000000000

def switch01(s, start, end):
    s = list(s)
    for i in range(start,end):
        if s[i] == '0':
            s[i] = '1'
        else:
            s[i] = '0'
    return ''.join(s)



while True:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            count += 1
        else:
            if count > maxc:
                maxc = count
                maxp = i-count+1
            count = 1
    tmp = [maxp,maxc,len(s)-maxc-maxp]
    if max(tmp) == maxp:
        if smax > max(tmp):
            smax = max(tmp)
        s = switch01(s,0,maxp)
    elif max(tmp) == maxc:
        if smax > max(tmp):
            smax = max(tmp)
        s = switch01(s,maxp,maxp+maxc)
    else:
        if smax > max(tmp):
            smax = max(tmp)
        s = switch01(s,maxp+maxc,len(s))
            
    if s == '0'*len(s) or s == '1'*len(s):
        break
        
print(smax)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 1
maxc = 1
maxp = 0
BR = True
smax = 10000000000

def switch01(s,i):
    s = list(s)
    if s[i] == '0':
        s[i] = '1'
    else:
        s[i] = '0'
    return ''.join(s)



while True:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            count += 1
        else:
            if count > maxc:
                maxc = count
                maxp = i-count+1
            count = 1
    tmp = [maxp,maxc,len(s)-maxc-maxp]
    if max(tmp) == maxp:
        if smax > max(tmp):
            smax = max(tmp)
        for i in range(0,maxp):
            s = switch01(s,i)
    elif max(tmp) == maxc:
        if smax > max(tmp):
            smax = max(tmp)
        for i in range(maxp,maxp+maxc):
            s = switch01(s,i)
    else:
        if smax > max(tmp):
            smax = max(tmp)
        for i in range(maxp+maxc,len(s)):
            s = switch01(s,i)
            
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            BR &= True
        else:
            BR &= False
    if BR == True:
        break
        
print(smax)

Submission status: Time Limit Exceeded

Solution code:
import sys

change = True
debug = False


def print_err(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def main():
    """
    0 と 1 からなる文字列 S が与えられます。
    以下の操作を好きな回数繰り返すことで S の要素をすべて 0 にできるような、|S| 以下の最大の整数 K を求めてください。
    S の長さ K 以上の連続する区間 [l,r] を選ぶ(すなわち、r−l+1≥K が満たされる必要がある)。
    l≤i≤r なるすべての整数 i に対し、Si が 0 なら Si を 1 に、Si が 1 なら Si を 0 に置き換える。
    制約
    1≤|S|≤105
    Si(1≤i≤N) は 0 または 1 である
    """
    S = input()

    f(S)


def f(S):
    """
    最大となるKより、1つずつ変えるのは最後の手段
    ※K以上の反転可能であるため

    000: OK
    001, 110:  -> 100, 011
    010, 101:
      11を最終的に反転するように修正していく
        101: 1-3 all
        011: 1-2
        000: 2-3
    011, 100: 11を反転でOK

    0001 となっているとき
    K=3とすれば
    000 をまず反転、その後K+1まで反転すれば、初期状態からK+1番目のみ反転できる
    """
    n = len(S)
    ans = n

    # 反転確認
    table = str.maketrans('01', '10')
    for k in range(1, n):
        if S[k] == S[k - 1]:
            continue

        t = max(k, n - k)
        ans = min(ans, t)

        # 反転を利用して異なる部分を変更
        # 要素数の多い方を対称の異なる文字含めて反転

        # CPython3: TLE
        if change:
            if t == k:
                S = S[:t].translate(table) + S[t:]
            else:
                S = S[:k] + S[k:].translate(table)

            if debug:
                print_err("t:", t, "k:", k, "S:", S, sep="\t")

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def print_err(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


def main():
    """
    0 と 1 からなる文字列 S が与えられます。
    以下の操作を好きな回数繰り返すことで S の要素をすべて 0 にできるような、|S| 以下の最大の整数 K を求めてください。
    S の長さ K 以上の連続する区間 [l,r] を選ぶ(すなわち、r−l+1≥K が満たされる必要がある)。
    l≤i≤r なるすべての整数 i に対し、Si が 0 なら Si を 1 に、Si が 1 なら Si を 0 に置き換える。
    制約
    1≤|S|≤105
    Si(1≤i≤N) は 0 または 1 である
    """
    S = input()

    f(S)


def f(S):
    """
    最大となるKより、1つずつ変えるのは最後の手段
    ※K以上の反転可能であるため

    000: OK
    001, 110:  -> 100, 011
    010, 101:
      11を最終的に反転するように修正していく
        101: 1-3 all
        011: 1-2
        000: 2-3
    011, 100: 11を反転でOK

    0001 となっているとき
    K=3とすれば
    000 をまず反転、その後K+1まで反転すれば、初期状態からK+1番目のみ反転できる
    """
    n = len(S)
    ans = n

    # 反転確認
    table = str.maketrans('01', '10')
    for k in range(1, n):
        if S[k] == S[k - 1]:
            continue

        t = max(k, n - k)
        ans = min(ans, t)

        t = max(k, n - k)
        # 反転を利用して異なる部分を変更
        # 要素数の多い方を対称の異なる文字含めて反転
        if t == k:
            S = S[:t].translate(table) + S[t:]
        else:
            S = S[:k] + S[k:].translate(table)

        print_err("t:", t, "k:", k, "S:", S, sep="\t")

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=len(S)
K=n
while(True):
    a=n-K
    b=K
    flag=1
    for i in range(a,b-1):
        if S[i]!=S[i+1]:
            flag=0
            break
    if flag==1:
        break
    else:
        K-=1
print(K)

Submission status: Time Limit Exceeded

Solution code:
s=input()
count=1
counted=[]
ans=0
answer_answer=100000000
maxcount=0
if len(s)==1:
  print(1)
else:
    for i in range(1,len(s)):

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve1(s, cache={}):
    n = len(s)
    if n == 1:
        return 1
    r = n
    while 1:
        i = 1
        while i < n:
            if s[i] != s[0]:
                for k in range(i):
                    s[k] = s[i]
                break
            if s[-i-1] != s[-1]:
                for k in range(i):
                    s[-k-1] = s[-i-1]
                break
            i += 1
        if n == i:
            break
        r = min(r, n - i)
    return r


line = sys.stdin.readline().strip()
print(solve1(list(line)))

Submission status: Time Limit Exceeded

Solution code:
s=input()
count=1
counted=[]
ans=0
answer_answer=100000000
maxcount=0
if len(s)==1:
  print(1)
else:
    for i in range(1,len(s)):

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

Submission status: Time Limit Exceeded

Solution code:
def po(tmp,i,j):
  str=tmp.copy()
  for k in range(i,j):
    if str[k]=='0':str[k]='1'
    else:str[k]='0'
  return str

s=list(input())
l=len(s)
while l:
  o,c=[s],[]
  while len(o)!=0:
    t=o[0]
    for i in range(l,len(s)+1):
      for j in range(len(s)-i+1):
        tmp=po(t,j,i+j)
        if tmp==["0"]*len(s):
          print(l);exit()
        if tmp not in o+c:o.append(tmp)
    c.append(o[0])
    o=o[1:]
  l-=1

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = tuple(map(int,tuple(input())))

n=0
ls = len(S)

while True:
    if n*2 >= ls:
        break
    sub = S[n:ls-n]
    s_sum = sum(sub)
    if s_sum is 0 or s_sum is len(sub):
        break
    n=n+1
print(ls-n)

Submission status: Time Limit Exceeded

Solution code:
import sys

inv = {"0": "1", "1": "0"}

def solve(s, cache={}):
    n = len(s)
    if n == 1:
        return 1
    i = 1
    while i < n and s[i] == s[0]:
        i += 1
    j = 1
    while j < n and s[-j-1] == s[-1]:
        j += 1
    if i == n:
        return n
    if i < j:
        rs = n - i
        ss = s[:i] + "".join([inv[c] for c in s[i:]])
        return min(solve(ss), rs)
    else:
        rs = n - j
        ss = "".join([inv[c] for c in s[:-j]]) + s[-j:]
        return min(solve(ss), rs)

line = sys.stdin.readline().strip()
print(solve(line))

Submission status: Time Limit Exceeded

Solution code:
A=list(map(int,list(input())))
L = len(A)
num = L
while True:
    pre = A[0]
    end = True
    for i in range(1,L):
        if A[i] != pre:
            if i*2 < L and L - i < num:
                num = L - i
            elif i < num:
                num = i
            for j in range(i):
                A[j] = 1 - A[j]
            end = False
            break
    if end:
        break
print(num)

Submission status: Time Limit Exceeded

Solution code:
A=list(input())
L = len(A)
num = L
while True:
    pre = A[0]
    end = True
    for i in range(1,L):
        if A[i] != pre:
            if i*2 < L and L - i < num:
                num = L - i
            elif i < num:
                num = i
            for j in range(i):
                A[j] = '0' if A[j] == '1' else '1'
            end = False
            break
    if end:
        break
print(num)

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=len(S)
K=n
while(True):
    a=n-K
    b=K
    flag=1
    for i in range(a,b-1):
        if S[i]!=S[i+1]:
            flag=0
            break
    if flag==1:
        break
    else:
        K-=1
print(K)

Submission status: Time Limit Exceeded

Solution code:
S=input()
m=list(map(len,S.split("0")))
while 0 in m:
    m.remove(0)
n=list(map(len,S.split("1")))
while 0 in n:
    n.remove(0)
print(max(sum(m),sum(n)))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

s = list(str(input()))

max_ = len(s)
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        left = i+1
        right = len(s)-left
        # print(left, right)
        tmp = max(left, right)

        max_ = min(max_, tmp)
print(max_)

Submission status: Accepted

Solution code:
S = list(input())
l = len(S)
S1 = S[:l//2][::-1]
S2 = S[l-l//2:]
ans = (l+1)//2
c = S[l//2]
for i in range(l//2):
    if S1[i] == c and S2[i] == c:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
def main():
    S = input()
    l = len(S)
    ans = l
    #データ加工
    for i, s in enumerate(S[1:]):
        if s != S[i]:
            ans = min(ans, max(i+1, l-1-i))
    print(ans)
    
main()

Submission status: Accepted

Solution code:
s=input()
inf=10**10
t=inf

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

if t==inf:
    print(len(s))
else:
    print(t)

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()
N = len(S)
if N == 1:
  print(1)
  exit()
if N%2:
  c = S[N//2]
  l,r = N//2-1,N//2+1
  ans = N//2+1
  while l>=0 and c == S[l] == S[r]:
    ans += 1
    l -= 1
    r += 1
  print(ans)
else:
  ans = N//2
  l,r = N//2-1,N//2
  while l>=0 and S[l] == S[r] == S[l+1]:
    ans += 1
    l -= 1
    r += 1
  print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
cnt = [0]
now = '0'
for i in S:
    if now == i:
        cnt[-1] += 1
    else:
        cnt.append(1)
        now = i

ans = len(S)
sum = 0
for i in cnt:
    sum += i
    ans = min(ans, max(sum, len(S) - sum))
print(ans)

Submission status: Accepted

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)

sum_key = sum(key)
ans = 10000000
for i in range(len(key)):
    if i != 0:
        key[i] += key[i-1]
    ans = min(ans, max(key[i], n-key[i]))
  

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(map(int, list(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-1))
print(ans)

Submission status: Accepted

Solution code:
import sys

readline=sys.stdin.readline

s=list(readline().strip())
n=len(s)
f=n%2
mid=s[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
l=len(S)
if l%2==1:
    m=S[l//2]
    c=1
    for i in range(l//2):
        if S[l//2-i-1]==m and S[l//2+i+1]==m:
            c+=2
        else:
            break
    ans=c+(l-c)//2
else:
    m1=S[l//2-1]
    m2=S[l//2]
    c=0
    if m1==m2:
        c=2
        for i in range(l//2-1):
            if S[l//2-i-2]==m1 and S[l//2+i+1]==m1:
                c+=2
            else:
                break
    ans=c+(l-c)//2
print(ans)

Submission status: Accepted

Solution code:
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

S = LI2()
N = len(S)

def f(n):  # n個ずつ反転するとき、左n個を同じ数字にできるか
    for i in range(N-n,n):
        if S[i] != S[n-1]:
            return False
    return True

left,right = (len(S)+1)//2,len(S)+1
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        left = mid
    else:
        right = mid
print(left)

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:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

S = input()
N = len(S)
ans = N
# 次の文字が違うところだけを見る
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: Accepted

Solution code:
#N = int(input())
S = str(input())
#X, Y = map(int, input().split())
#C = list(map(int, input().split()))
N  =len(S)
ans = N
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: Accepted

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

Submission status: Accepted

Solution code:
I = input()

n     = len(I)
left  = 0
right = n - 1

block_left_index  = 0
block_right_index = n

## Example:
## 000011000
## |     |
##    or
##     |    |
while left < right:
    if I[left] != I[left+1]:
        block_left_index = left+1
    if I[right] != I[right-1]:
        block_right_index = right
    left  += 1
    right -= 1

ans = min(n-block_left_index, block_right_index)
print(ans, flush=True)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    """
    備忘録用に自分のコードの解説。
    まずすぐにKの値を決め打ち二分探索することを思いつく。
    なので任意のKに対して、K文字以上の連続する区間を何回かフリップしてSを"000...0"にできるか判定できれば良い。

    ここで、Sの文字を0-indexedで添え字づけした時にK文字目以降は任意の１桁をフリップできることに気づく。
    というのも例えばm文字目(K <= m)をフリップしたければ[0, m-1], [0, m]の２区間をフリップすれば良い。
    同様に末尾からも考えると、0以上(|S|-K)未満の任意の１桁も自由にフリップできる。

    これよりK=|S|//2の時は必ずSを"000...0"にできることがわかる。
    ではKがこれより大きい時はどうなるだろうか？
    この時自由にフリップができない区間S[(|S|-K):K]が出現する。
    そして2つ目の気づきとして、この区間はどんな区間長K以上のフリップをかけても必ず全体のビットが反転する！

    以上より
        「区間長K以上のフリップをかけてSを"000...0"にできる」
         = 「中央区間S[(|S|-K):K]のビットが全て等しい」
    が結論となる。
    """
    S = input()
    N = len(S)
    if S == '1' * N or S == '0' * N:
        print(N)
        return
    left = N // 2
    right = N
    while right - left > 1:
        mid = (left + right) // 2
        if S[(N - mid):mid] == '1' * (2 * mid - N) or S[(N - mid):mid] == '0' * (2 * mid - N):
            left = mid
        else:
            right = mid
    print(left)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    N = len(S)
    if S == '1' * N or S == '0' * N:
        print(N)
        return
    left = N // 2
    right = N
    while right - left > 1:
        mid = (left + right) // 2
        if S[(N - mid):mid] == '1' * (2 * mid - N) or S[(N - mid):mid] == '0' * (2 * mid - N):
            left = mid
        else:
            right = mid
    print(left)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    l = len(s)
    ans = l
    for i in range(1, l):
        if s[i] != s[i - 1]:
            ans = min(ans, max(l - i, i))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

S = readline().rstrip()

ans = len(S)
for i in range(1,len(S)):
  if S[i] != S[i - 1]:
    longer = max(i, len(S) - i)
    if ans > longer:
      ans = longer
      
print(ans)

Submission status: Accepted

Solution code:
S = input()
L = len(S)
now = S[0]
ok = True
ans = 10**18
for i in range(1, L):
    if S[i] != now:
        now = S[i]
        ans = min(ans, max(i, L-i))
        ok = False
if ok:
    print(L)
else:
    print(ans)