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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import bisect
from logging import getLogger, StreamHandler, DEBUG, WARNING
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
# handler.setLevel(WARNING)
# logger.setLevel(WARNING)
logger.addHandler(handler)
def main():
    s = input().strip()
    n = len(s)
    tmp = s[0]
    ans = 0
    for i , c in enumerate(s):
        if tmp != c:
            if i > ans:
                ans = i

        if i >= (n) // 2:
            break
        tmp = c


    tmp = s[-1]
    for i, c in enumerate(s[::-1]):
        if tmp != c:
            if i > ans:
                ans = i

        if i >= (n) // 2:
            break
        tmp = c

    print(n - ans)

    # print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def bisection(l,r,f,left=True,discrete=True):
    eps=1 if discrete else 10**-12
    if((not left)^f(r)): return r if left else r+1
    elif(left^f(l)): return l-1 if left else l
    while(r-l>eps):
        h=(l+r)//2 if discrete else (l+r)/2
        if((not left)^f(h)): l=h
        else: r=h
    return (l+r)/2 if not discrete else l if left else r

def resolve():
    S=input()
    n=len(S)

    def check(k):
        if(n-k>=k): return True
        else: return len(set(S[n-k:k]))==1

    print(bisection(1,n,check))
resolve()

Submission status: Accepted

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

K = N // 2

if N % 2 == 0:
    if S[K - 1] == S[K]:
        tmp = S[K - 1]
    else:
        print (K)
        exit()
    i = 0
    while i < K and S[K - 1 - i] == S[K + i] == tmp:
        i += 1
    print (K + i)
else:
    tmp = S[K]
    i = 1
    while i <= K and S[K - i] == S[K + i] == tmp:
        i += 1
    print (K + i)

Submission status: Accepted

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

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

k = N

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

Submission status: Accepted

Solution code:
s = input()
i = (len(s) - 1) // 2
j = len(s) // 2
k = s[i]
while i >= 0:
  if s[i] != k or s[j] != k:
    break
  i -= 1
  j += 1
if i <  0:
  print(len(s))
else:
  print(j)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = list(input())
N = len(S)

ans = ceil(N, 2)
for i in range(ceil(N, 2), N):
    # 真ん中から始めて、反対側と一致してるかと、1つ前と一致しているか
    if not S[i] == S[N-1-i] == S[i-1]:
        break
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

s = S()
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:
S = input()

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

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

Submission status: Accepted

Solution code:
# D 3424320
S = input()
N = len(S)
center_i = N//2
center = S[center_i]

ans = N//2
l = r = center_i
if N%2==0:
    l -= 1
while l >= 0:
    if not (S[l] == center == S[r]):
        break
    l -= 1
    r += 1
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# [a,b] - [a,b) = {b} なので、端の方は自由。
# 中央が単色であるかを確認すればよい。

import numpy as np
arr = np.array([int(x) for x in input()])
arr_c = arr.cumsum()

N = arr.size

answer = 0

for K in range(N,0,-1):
  left = N-K
  right = K-1
  # [left,right]が単色であればよい
  if left >= right:
    answer = K
    break
  one_cnt = arr_c[right] - arr_c[left] + arr[left]
  zero_cnt = (right - left + 1) - one_cnt
  if one_cnt == 0 or zero_cnt == 0:
    answer = K
    break
    
print(answer)

Submission status: Accepted

Solution code:
S=list(input())
n=len(S)
ans=n
for _ in range(n-1):
	if S[_]!=S[_+1]:
		tmp=max(_+1,n-(_+1))
		ans=min(ans,tmp)

print(ans)

Submission status: Accepted

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

l, r, p = 0, 0, s[L // 2]
if L % 2 == 0:
    l, r = L // 2 - 1, L // 2
else:
    l, r = L // 2, L // 2

cnt = 0
while l >= 0 and r < L and s[l] == s[r] == p:
    p = s[l]
    cnt += 1
    l -= 1
    r += 1

print(cnt + L // 2)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
l = 0
a = {}
if N%2==0:
    if S[N//2] != S[N//2-1]:
        print(N//2)
    else:
        flag = S[N//2]
        l = 2
        i = 1
        while i <= N//2-1:
            if S[N//2+i]==flag and S[N//2-1-i]==flag:
                l+=2
                i += 1
            else:
                break
        print(N//2+l//2)
else:
    flag = S[N//2]
    i = 1
    l = 1
    while i <= N//2:
        if S[N//2+i]==flag and S[N//2-i]==flag:
            l += 2
            i += 1
        else:
            break
    print((N-l)//2 + l)

Submission status: Accepted

Solution code:
import itertools
S = list(itertools.accumulate([0] + [int(_) for _ in input()]))
N = len(S) - 1
for i in range(N, 0, -1):
    if 2 * i < N:
        break
    if S[i] - S[N - i] in [0, 2 * i - N]:
        break
print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c, d = LI()
    a += b
    c += d
    ans = ["Left", "Right"]
    if a == c:
        print("Balanced")
        return
    print(ans[a < c])
    return

#B
def B():
    n, a, b = LI()
    ans = 0
    for i in range(1, n + 1):
        if a <= sum(list(map(int, list(str(i))))) <= b:
           ans += i
    print(ans) 
    
    return

#C
def C():
    x, y = LI()
    ans = 0
    while x <= y:
        ans += 1
        x *= 2
    print(ans)
    return

# D
# 解説AC
# 実はi,i+1番目を順にみて文字が異なるなら
# max(i,n-k)文字を入れ替えればいいのである
def D():
    s = S()
    ans = inf
    n = len(s)
    for i in range(n - 1):
        if s[i] != s[i + 1]:
            ans = min(ans, max(i + 1, n - i - 1))
    print(ans if ans != inf else n )
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

Solution code:
S = input()

## 0を基準として、0と1の境目を調べる
boundary = []
pre_state = '0'
for i in range(len(S)):
  if S[i] != pre_state:
    boundary.append(i)
    pre_state = S[i]
else:
  if S[-1] == '1':
    boundary.append(len(S))
    
if len(boundary) == 0:
  print(len(S))
  exit()
    
## 答えは、端から一番遠い境目
lst = []
for i in range(len(boundary)):
  lst.append(max(boundary[i], len(S)-boundary[i]))
ans = min(lst)
print(ans)

Submission status: Accepted

Solution code:
S = input()
c0 = S[len(S)//2]
r = S.find("1" if c0 == "0" else "0", len(S)//2)
if r < 0: r = len(S)
l = S.rfind("1" if c0 == "0" else "0", 0, len(S)//2)
l += 1
K = min(r, len(S)-l)
#print(l, r, K)
print(K)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
"""
s = '101'
s = '100000000'
s = '00001011'
"""
k = len(s)
for i in range(1, len(s)):
    if s[i-1] != s[i]:
        k = min(k, max(i, len(s)-i))
print(k)

Submission status: Accepted

Solution code:
S = input()
b = []
for i in range(len(S) - 1):
    if S[i:i + 2] == "01" or S[i:i + 2] == "10":
        b.append(len(S) - (i + 1) if i < len(S) // 2 else i + 1)

print(min(b) if len(b) != 0 else len(S))

Submission status: Accepted

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

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

def f(k):
    s = S[-k:k]
    if s == "":return False
    return s.count(s[0])!=len(s)

def binary_search(l,r,func):
    if func(l):return l-1
    if not func(r):return r
    while l+1<r:
        i = (l+r)//2
        if func(i):
            r = i
        else:
            l = i
    return l

print(binary_search(0,N,f))

Submission status: Accepted

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)
ma=a[0];mb=b[0]
for t in range(1,l+1):
	ma=max(ma,a[t-1])
	mb=max(mb,b[t-1])
	m=min(ma,mb)
	if l-m<t:
		print(t-1)
		exit()
print(l)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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(max(len(S) - i - 1, i + 1),ans)
print(ans)

Submission status: Accepted

Solution code:
S = input()

l = (len(S)-1)//2
r = len(S)//2
m = S[l]
while l >= 0:
    if S[l] != m or S[r] != m:
        break
    l -= 1
    r += 1
if l < 0:
    print(len(S))
else:
    print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ans = len(S)// 2
if len(S) % 2 == 1:
    ans += 1

t = S[len(S)//2]
c = ans
for i in range(len(S)//2-1,-1,-1):
    if S[i] == S[c] and S[i] == t:
        ans += 1
        c += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2+1
    c = ans
    t = S[ans-1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break


print(ans)

Submission status: Accepted

Solution code:
S = input()

ans = 0
if len(S) % 2 == 0:
    ans = len(S)//2
    c = ans
    t = S[ans]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break
else:
    ans = len(S)//2+1
    c = ans
    t = S[ans-1]
    for i in range(len(S)//2-1,-1,-1):
        if S[i] == S[c] and S[i] == t:
            ans += 1
            c += 1
        else:
            break

    ans = max(len(S)//2,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()
length = len(s)
if length == 1:
    print 1
    exit()
T = []
for i in range(length-1):
    if s[i] != s[i+1]:
    	T.append(max(i+1, length-(i+1)))
if len(T) == 0:
    print length
else:
    print min(T)

Submission status: Accepted

Solution code:
S=input()
l=len(S)
cnt=(l+1)//2
n=l-cnt
b=S[l//2]
if l%2==0:
    for i in range(n):
        if S[l//2-i-1]!=b or S[l//2+i]!=b:
            break
        cnt+=1
else:
    for i in range(n):
        if S[l//2-i-1]!=b or S[l//2+i+1]!=b:
            break
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
if n%2==0:
    ans=n//2
    if s[n//2-1]==s[n//2]:
        ans=ans+1
        a=s[n//2]
        x=n//2-1
        y=n//2
        while True:
            if x==0:
                break
            x,y=x-1,y+1
            if s[x]==a and s[y]==a:
                ans=ans+1
            else:
                break
else:
    a=s[(n-1)//2]
    ans=(n-1)//2+1
    x=(n-1)//2
    y=(n-1)//2
    while True:
        if x==0:
            break
        x,y=x-1,y+1
        if s[x]==a and s[y]==a:
            ans=ans+1
        else:
            break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc083/submissions/1917434
# i i+1 が異なる場所は中間から探すだけでいい
s=input()
a=s[(len(s)-1)//2::-1]
b=s[len(s)//2:]
if a[0]!=b[0]:
    print(len(s)//2)
else:
    c=str(1-int(a[0]))
    m = (a+c).find(c)
    n = (b+c).find(c)
    print(len(s)//2+min(m,n))

Submission status: Accepted

Solution code:
S = input()
if S.count('1') == 0 or S.count('0') == 0:
    print(len(S))
    exit()

c = S[0]
len_s = len(S)
mx = len_s
for s in range(1,len_s):
    if c != S[s]:
        mx = min(mx, max(len_s -s, s))
    c = S[s]
print(mx)

Submission status: Accepted

Solution code:
S = str(input())
L = len(S)
valueChangedIndex = []
s = S[0]
for i in range(1, L):
    if S[i] != s:
        valueChangedIndex.append(max(i, L-i))
    s = S[i]

if len(valueChangedIndex) == 0:
    print(L)
else:
    print(min(valueChangedIndex))

Submission status: Accepted

Solution code:
S = input()

mi = len(S) // 2 + len(S) % 2 

if len(S) % 2 == 0:
  l = mi - 1
  r = mi
  if S[l] != S[r]:
    print(r)
    exit()
else:
  l = mi - 1
  r = mi - 1

re = S[l]
for i in range(l):
  if S[l - 1 - i] != re or S[r + 1 + i] != re:
    ans = r + i + 1
    break
else:
  ans = len(S)


print(ans)

Submission status: Accepted

Solution code:
S=input()
if len(S)==1:
    print(1)
    quit()
if len(S)%2==0:
    A=S[:len(S)//2]
    B=S[len(S)//2:]
    A=A[::-1]
    s=A[0]
    ans=len(S)//2
if len(S)%2==1:
    A=S[:len(S)//2]
    B=S[len(S)//2+1:]
    A=A[::-1]
    s=S[len(S)//2]
    ans=len(S)//2+1
for i in range(len(A)):
    if A[i]!=s or B[i]!=s:
        print(ans+i)
        quit()
print(len(S))

Submission status: Accepted

Solution code:
import math

def main():
    data = list(input())
    pre = data[0]
    ans = len(data)
    for i in range(1, len(data)):
        if pre != data[i]:
            ans = min(ans, max(i, len(data) - i))
            pre = data[i]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import*;s=input();print(min(max(len(s)-i,i)for i in accumulate(len(list(v))for k,v in groupby(s))))

Submission status: Accepted

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    bound=0
    ans=[]
    s=input()
    for k,v in groupby(s):
        bound+=len(list(v))
#        ans.append()
        ans.append(max(bound,len(s)-bound))
    print(min(ans))
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    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)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()



tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

if len(tmp) == 0:
        #元から全部同じ
        print(len(s))
else:
        print(min(tmp))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):

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


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ss=s[0]
C=[]
for i in range(1,n):
  if s[i]!=ss:
    C.append(max(i,n-i))
  ss=s[i]
print(n if len(C)==0 else min(C))

Submission status: Accepted

Solution code:
S = input()

e = '0'
s = 0
li = []
for v in S:
  if v == e:
    s += 1
  else:
    li.append(s)
    s = 1
    e = v
if ( s > 0):
  li.append(s)

lis = [0]*( len(li) + 1 )
for i in range(len(li)):
  lis[i+1] = lis[i] + li[i]

gg = lis[-1]
sm = 100000000000000000000
for v in lis:
  sm = min(sm,max(v,gg-v))
print ( sm )

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n%2 == 0:
  a = n//2 - 1
  b = n//2
  c = 2
  d = s[a]
  if s[b] != d:
    print(n//2)
    quit()
else:
  a = n//2
  b = n//2
  c = 1
  d = s[a]
while a-1 >= 0 and s[a-1] == d and s[b+1] == d:
  a -= 1
  b += 1
  c += 2
print(n-(n-c)//2)

Submission status: Accepted

Solution code:


s = input()

size = len(s)
ans = size

for i in range(size-1):

    if s[i] != s[i+1]:
#        print((i+1,size-i-1))
        t = max(i+1,size-i-1)

        ans = min(ans,t)

print(ans)

Submission status: Accepted

Solution code:
def main():
    s = input()
    i = j = len(s) // 2
    if len(s) % 2 == 0:
        j -= 1
    ss = s[j]
    while len(s) > i and j >= 0 and ss == s[i] and ss == s[j]:
        i += 1
        j -= 1
    print(i)


main()

Submission status: Accepted

Solution code:
S = input()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

la=[0]
lb=[0]

for i in s:
    if i=="0":
        la.append(la[-1]+1)
        lb.append(lb[-1])
    else:
        lb.append(lb[-1]+1)
        la.append(la[-1])

if n%2==0:
    for i in range(n//2+1):
        if la[n//2+i]-la[n//2-i]==0 or lb[n//2+i]-lb[n//2-i]==0:
            ans=n//2+i
else:
    for i in range(n//2+1):
        if la[n//2+i+1]-la[n//2-i]==0 or lb[n//2+i+1]-lb[n//2-i]==0:
            ans=n//2+i+1

print(ans)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans = len(S)
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:
import math

S = input()
N = len(S)

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

SUM = cntl[0]
ans = max(N-cntl[0],N-cntl[-1])
for i in range(1,len(cntl)-1):
  ans = min(ans,min(N-SUM,SUM+cntl[i]))
  SUM += cntl[i]
"""
if ans == 0:
  print(N)
else:
  print(ans)
"""
SSUM = 0
for i in cntl:
  SSUM += i
  if SSUM >= math.ceil(N/2):
    print(min(SSUM,N-(SSUM-i)))
    break

Submission status: Accepted

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

prev = None
cand = []
for i in range(n):
    if i != 0:
        if S[i] != prev:
            cand.append(max(i, n-i))
    prev = S[i]    
if cand:
    print(min(cand))
else:
    print(n)

Submission status: Accepted

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

import sys
input = sys.stdin.readline

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	s=list(io())[:-1]
	if len(s)% 2==1:
		center=len(s)//2
		mm=s[center]
		ret=center+1
		la=s[center-1::-1]
		lb=s[center+1:]
		for ca,cb in zip(la,lb):
			#print(ca,cb,mm)
			if ca == mm and cb == mm:
				ret += 1
			else:
				break
	else:
		center=len(s)//2
		ret=center
		mm=-1
		la=s[center-1::-1]
		lb=s[center:]
		for ca, cb in zip(la, lb):
			if (mm == ca or mm == -1) and ca == cb:
				ret+=1
				mm=ca
			else:
				break
				
	if 0:
		print(la)
		print(lb)
		print(mm)
	return ret

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Accepted

Solution code:
s = input()
if len (s) % 2 == 1:
    l = r = (len(s) + 1) // 2
    k = l-1
else:
    l = len(s) // 2
    r = len(s) // 2 + 1
    k = l
center = s[l-1]

while s[l-1] == center and s[r-1] == center:
    k += 1
    l -= 1
    r += 1
    if l - 1 < 0:
        break

print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

l = len(s)

if l%2:
    #odd
    center = s[l//2]
    res = l//2+1
    for i in range(1,l//2+1):
        if s[l//2-i]==s[l//2+i] and s[l//2-i]==center:
            res+=1
        else:
            break
    print(res)
else:
    center = s[l//2]
    res = l//2
    for i in range(1,l//2+1):
        if s[l//2-i]==center and center == s[l//2+i-1]:
            res+=1
        else:
            break
    print(res)

Submission status: Accepted

Solution code:
def solve(string):
    l = [s == "1" for s in string]
    l_r = l[::-1]
    index = 0
    h = len(string) // 2
    for i, (c, n, c_r, n_r) in enumerate(zip(l[:h], l[1:h + 1], l_r[:h], l_r[1:h + 1])):
        if c ^ n or c_r ^ n_r:
            index = i + 1
    return str(len(string) - index)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    x,y = LI()
    ans = 1
    for i in range(10000000000000):
        x *= 2
        if x > y:break
        ans += 1
    print(ans)

#D
def D():
    s = S()
    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)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()