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

#print(S)

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

Submission status: Accepted

Solution code:
s=input()
pre=s[0]
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)))
    pre=s[i]
print(ans)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    L = len(S)

    i = 0
    if L % 2 == 1:
        mid = (L - 1) // 2
        m = S[mid]
        while i <= mid and S[mid-i] == S[mid+i] == m:
            i += 1

        print(mid + i)
    else:
        mid =  (L - 1) // 2
        m0 = S[mid]
        m1 = S[mid+1]
        while i <= mid and S[mid-i] == S[mid+i+1] == m0 == m1:
            i += 1

        print(mid + i + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
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:
def main():
    S = input()
    N = len(S)
    ans = N
    for i in range(1, N):
        if S[i-1] != S[i]:
            ans = min(ans, max(i, N-i))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import exit
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
cnt = 0
num0 = 0
num1 = 0
ans = L
for i in range(0,L-1):
    if S[i] != S[i+1]:
        ans = min(ans,max(i+1,L-(i+1)))
print(ans)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
if l % 2:
    c = s[l//2]
    ans = l
    for i in range(1, l//2+1):
        if s[l//2 - i] != c or s[l//2 + i] != c:
            ans = i + l//2
            break
else:
    if s[l//2-1] != s[l//2]:
        ans = l//2
    else:
        ans = l
        c = s[l//2]
        for i in range(1, l//2):
            if s[l//2 - i - 1] != c or s[l//2 + i] != c:
                ans = l//2 + i
                break
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:
S = input()
N = len(S)
even=(N%2==0) 
a=N//2 + (not even) 
b=a

for i in range(N//2-even, N-1):
  if S[i]!=S[i+1]:
    break 
  else:
    b+=1
for i in range(N//2,0,-1): 
  if S[i]!=S[i-1]:
    break 
  else:
    a+=1
ans=min(a,b ) 

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if t % 2 == 0 :  # 偶数文字
    ans = t // 2
    th = t // 2
    if s[th-1] == s[th] :
        ans += 1 
        b = s[th]
        l = th - 1 - 1
        r = th + 1
        while l >= 0 and r <= t-1 and s[l] == b and s[r] == b :
            ans += 1
            l -= 1
            r += 1
else :  # 奇数文字
    ans = t // 2 + 1
    th = t // 2
    
    b = s[th]
    l = th - 1
    r = th + 1
    while l >= 0 and r <= t-1 and s[l] == b and s[r] == b :
        ans += 1
        l -= 1
        r += 1
        
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
k = 0
tmp = set()
while k * 2 < n and len(tmp) < 2:
    tmp.add(s[n // 2 + k])
    tmp.add(s[(n - 1) // 2 - k])
    k += 1
print(n // 2 + k - (len(tmp) == 2))

Submission status: Accepted

Solution code:
s = input()

n = len(s)
ans = n
for i, (c1, c2) in enumerate(zip(s[:-1], s[1:])):
    if c1 == c2:
        continue
    ans = min(ans, max(i + 1, n - i - 1))

print(ans)

Submission status: Accepted

Solution code:
S=input()
l=len(S)
a=[l]
for i in range(l-1):
    if S[i]!=S[i+1]:
        a.append(max(i+1,l-i-1))
print(min(a))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
if len(s)%2==0:
  a = len(s)//2-1
  b = len(s)//2
else:
  a=b=len(s)//2
ans = b
cs = s[b]
while (a>0):
  if s[a] == cs and s[b] == cs:
    ans += 1
    a -= 1
    b += 1
  else:
    break

L = [0]
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    L.append(i + 1)
L.append(len(s))
LL = [0]
for i in range(len(L) - 1):
  LL.append(L[i+1] - L[i])
LL.append(0)
ma = 0
for i in range(len(LL) - 2):
  ma = max(ma,LL[i+1] + min(LL[i], LL[i+2]))

print(max(ma, ans))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
if N % 2 == 0:
    if S[N//2] != S[N//2-1]:
        print(N-N//2)
        exit()
    tmp = S[N//2]
    ans = N-N//2
    l = N//2-1
    r = N//2
    while S[l] == tmp and S[r] == tmp:
        ans += 1
        l -= 1
        r += 1
        if l < 0 or r > N-1:
            break
    print(ans)
else:
    tmp = S[N//2]
    ans = N-N//2-1
    l = N//2
    r = N//2
    while S[l] == tmp and S[r] == tmp:
        ans += 1
        l -= 1
        r += 1
        if l < 0 or r > N-1:
            break
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

"""
参考：https://img.atcoder.jp/arc088/editorial.pdf
・一番真ん中に近い境界の、始点か終点の遠い方の距離が最適
・中央付近から順に境界を1つずつ減らして最終的に全0にできる。
"""

S = input()

dist = float('inf')
for i in range(1, len(S)):
    if S[i] != S[i-1]:
        # 境界を見つけたら、始点か終点の遠い方の距離を取る
        tmp = max(i, len(S)-i)
        # この値が小さい程中央に近い位置
        if tmp < dist:
            dist = tmp
# 境界が1つもないなら、文字列の長さをそのまま使える
if dist == float('inf'):
    dist = len(S)

print(dist)

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:
#!/usr/bin/env python3

def main():
    S = input()

    len_S = len(S)
    i = j = j0 = int(len_S / 2)
    if len_S % 2 == 0:
        i -= 1

    c = S[i]
    while 0 <= i and j < len_S and c == S[i] and c == S[j]:
        i -= 1
        j += 1

    print(j)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if s[0]*n==s:
    print(n)
    exit()
res = []
for i,(a,b) in enumerate(zip(s,s[1:])):
    if a != b:
        res.append(max(i+1,n-1-i))
print(min(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s=input()
len_s=len(s)
if(len_s==1):
    print(1)
    sys.exit()


if(len_s%2==1):
    l=len_s//2
    r=l
else:
    r=len_s//2
    l=r-1

saisyo=s[l]
if(s[l]==s[r]):
    while(0<l and saisyo==s[l-1] and saisyo==s[r+1]):
        l-=1
        r+=1

else:
    r=l

print( (len_s + r-l +1)//2)

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 = list(map(int, 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()
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()
is_odd=len(S)%2
mid1=(len(S)-1)//2
mid2=(len(S))//2
ans=mid2
tmp=S[mid1]
for i in range(mid1+1):
    if tmp==S[mid1-i] and tmp==S[mid2+i]:
        ans+=1
    else:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(T)

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

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

print(t)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
n = len(s)

fst = 0
lat = 0
ans = 0

if n % 2:
    fst = s[n//2::-1]
    lat = s[n//2:]
    ans = n//2 + 1

else:
    fst = s[n//2::-1]
    lat = s[n//2-1:]
    ans = n//2
  
for i in range(len(fst)-1):
    if fst[0] != lat[0]:
        break
    
    if fst[i+1] == fst[i] and lat[i+1] == lat[i]:
        ans += 1
        
    else:
        break
        
print(ans)

Submission status: Accepted

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

if x%2==0:
    if S[x//2]!=S[x//2-1]:
        ANS=x//2

    else:
        base=S[x//2]

        for i in range(x//2):
            if S[x//2-1-i]!=base or S[x//2+i]!=base:
                ANS=x//2+i
                break

        else:
            ANS=x


else:
    base=S[x//2]

    for i in range(x//2+1):
        
        if S[x//2-i]!=base or S[x//2+i]!=base:
            ANS=x//2+i
            break

    else:
        ANS=x    


print(ANS)

Submission status: Accepted

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

t = [n]
for i in range(1, n):
    if s[i] != s[i-1]:
        t.append(max(i, n-i))
print(min(t))

Submission status: Accepted

Solution code:
s = raw_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()

i_flips = []
i = 0
for j in range(1, len(s)):
    if s[j] != s[i]:
        i_flips.append(j)
        i = j
# print(i_flips)

if len(i_flips) == 0:
    print(len(s))
else:
    ans = len(s)
    for i in i_flips:
        ans = min(ans, max(i, len(s)-i))
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(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()
best = len(S)
for i in range(1, len(S)):
    if S[i-1] != S[i]:
        best = min(best, max(i, len(S) - i))
print(best)

Submission status: Accepted

Solution code:
S=raw_input()
L=len(S)
ans=L


if L%2==0: loop=L/2
else: loop=L/2+1

prev=None
for i in range(loop):
#	print i,L-i-1,S[i],S[L-i-1],S[i]==S[L-i-1],ans
	if S[i]==S[L-i-1]:
		if prev is None:
			pass
		elif prev!=S[i]:
			ans=L-i
		prev=S[i]
	else:
		ans=L-i-1

print ans

Submission status: Accepted

Solution code:
S = input()
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:
import numpy as np
S = np.array([int(i) for i in input()])
N = len(S)
T = np.abs(np.diff(S))
K = N
for i in range(N // 2):
    if T[i] == 1 or T[N - 2 - i] == 1:
        K = N - i - 1

print(K)

Submission status: Accepted

Solution code:

#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()
    n = len(S)
    if n % 2 == 0:
        l, r = n // 2, n // 2 - 1
        ans = n // 2
    else:
        l, r = n // 2, n // 2
        ans = n // 2 + 1

    while 0 < l and r < n - 1:
        l -= 1
        r += 1
        if S[l] != S[l + 1] or S[r] != S[r - 1]:
            break
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

cums = [0] * (len(S)+1)

for i in range(len(S)):
  cums[i+1] = cums[i] + int(S[i])

ans = len(S)
l = 0
r = len(S)-1
#print(cums)
while l <= r:
  x = cums[r+1] - cums[l]
  #print(x,l,r)
  if x == (r-l+1) or x == 0:
    break
  ans -= 1
  l += 1
  r -= 1

print(ans)

Submission status: Accepted

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

ans = N//2 + bool(N%2)


# 奇数
if N%2 == 1:
    left = S[:N//2]
    left = left[::-1]
    right = S[N//2+1:]
    cent = S[N//2]
    
    i = 0
    while i < N//2:
        if left[i] == cent and right[i] == cent:
            ans += 1
            i += 1
        else:
            break
        
else:
    left = S[:N//2]
    left = left[::-1]
    right = S[N//2:]
    cent = S[N//2]
    
    i = 0
    while i < N//2:
        if left[i] == cent and right[i] == cent:
            ans += 1
            i += 1
        else:
            break
        
print(ans)

Submission status: Accepted

Solution code:
s = input()
if len(s)==1:
  print(1)
  exit()
ans = len(s)
tori = float("inf")
for i in range(1,len(s)):
  a = s[i]
  b = s[i-1]
  if a != b:
    tori = max(i,len(s)-i)
  ans = min(tori,ans)
print(ans)

Submission status: Accepted

Solution code:
s=list(input())

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

    print(min(a))

Submission status: Accepted

Solution code:

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(map(int, input().split()))

AA = list(map(int,list(input())))
L = len(AA)
ans = L
for i in range(1,L):
	if AA[i] != AA[i-1]:
		ans = min(ans,max(L-i,i))

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    N = len(S)
    ans = sys.maxsize
    for i in range(N-1):
        if S[i] != S[i+1]:
            ans = min(ans, max(i+1, N-i-1))

    if ans == sys.maxsize:
        return N
    return ans


def main():
    S = read_str().strip()
    # S = ''.join([random.choice('01') for _ in range(100000)])
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
min_T = N
for i in range(1, N):
    if S[i]!=S[i-1]:
        min_T = min(min_T, max(i, N-i))

print(min_T)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
k=0
if n%2==0:
  n2=int(n/2)
  k+=n2
  for i in range(n2):
    if '0' in s[n2-i-1:n2+i+1] and '1' in s[n2-i-1:n2+i+1]:
      break
    k+=1
  print(k)
else:
  n3=int((n-1)/2)
  k+=n3
  for i in range(n3+1):
    if '0' in s[n3-i:n3+i+1] and '1' in s[n3-i:n3+i+1]:
      break
    k+=1
  print(k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

S = list(map(int, input()))

#max_S = 0
#count = 1
#flag = 0
#
#for i in range(1, len(S)):
#    if S[i-1]==S[i]:
#        count += 1
#    else:
#        if max_S < count:
#            max_S = count
#        count = 1
#        flag += 1
#
#if max_S < count:
#    max_S = count
#
#if flag < 2:
#    max_S -= 1

N = len(S)


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

print(min_T)

Submission status: Accepted

Solution code:
S = list(input())

k = len(S) // 2 + 1
x = S[k - 1]
for i in range(k, len(S) + 1):
    if x != S[i - 1] or x != S[len(S) - i]:
        i -= 1
        break
print(i)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans = n//2
c = S[ans]

while ans < n:
    if c == S[ans] == S[-ans-1]:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

for k in range((len(s)+1)//2 + 1, len(s)+1):
    if s[k-1] != s[k-2] or s[-k] != s[-k+1]:
        print(k - 1)
        break
else:
    print(len(s))

Submission status: Accepted

Solution code:
S = input()

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

print(temp_T)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(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()
L = len(S)
A = len(S)
for i in range(1,L):
    if S[i] != S[i-1] and A > max(i,L-i):
        A = max(i,L-i)
print(A)

Submission status: Accepted

Solution code:
s = input()
if len(s)%2==1:
	letter,a,x,y = s[(len(s)-1)//2],(len(s)-1)//2,len(s),-1
	for i in range(a+1,len(s)):
		if letter != s[i]:
			x = i
			break
	for i in range(a-1,-1,-1):
		if letter != s[i]:
			y = i
			break
	print(min(x,len(s)-y-1))
else:
	if s[len(s)//2] != s[len(s)//2-1]: print(len(s)//2)
	else:
		letter,a,x,y = s[len(s)//2],len(s)//2,len(s),-1
		for i in range(a+1,len(s)):
			if letter != s[i]:
				x = i
				break
		for i in range(a-2,-1,-1):
			if letter != s[i]:
				y = i
				break
		print(min(x,len(s)-y-1))

Submission status: Accepted

Solution code:
def main():
    S = input()
    S_l = len(S)
    T = []

    for i in range(S_l-1):
        if S[i] != S[i+1]:
            T.append(max([i+1, S_l-i-1]))

    if T != []:
        return min(T)
    else:
        return S_l

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

import sys

def main():
    s = tuple(map(int, sys.stdin.readline().strip()))

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

    print(k)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=raw_input()
N=len(S)
c=len(S)/2


if N%2==1:
	cnt=c+1
	for i in range(1,c+1):
		if S[c-i]==S[c+i]==S[c]:
			cnt+=1
			pass
		else:
			break
else:
	cnt=c
	if S[c]!=S[c-1]:
		print cnt
		quit()
	cnt+=1
	for i in range(1,c):
		if S[c+i]==S[c-i-1]==S[c]:
			cnt+=1
		else:
			break

print cnt

Submission status: Accepted

Solution code:
S=raw_input()
N=len(S)
TS=N
for k in range(N-1):
	if S[k]!=S[k+1]:
		TS=min(TS, max(k+1, N-k-1))

print TS

Submission status: Accepted

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

Submission status: Accepted

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

S = input()
len_S = len(S)
K = len_S

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

Submission status: Accepted

Solution code:
S=input()

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

print(ans)

Submission status: Accepted

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

    minimum_t = 100000000
    pre_letter = S[0]

    for idx in range(1, N):
        if S[idx] != pre_letter:
            minimum_t = min(max(idx, N-idx), minimum_t)
            pre_letter = S[idx]
        else:
            continue

    if minimum_t == 100000000:
        print(N)
    else:
        print(minimum_t)

main()

Submission status: Accepted

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

print(T)

Submission status: Accepted

Solution code:
def ans():
    S = input()
    N = len(S)
    if not ('1' in S and '0' in S):
        return print(N)

    tmp = 1000000
    for i, v in enumerate(S):
        if i == 0:
            continue
        if S[i-1] != v:
            tmp = min(max(i, N-i), tmp)
    return print(tmp)

# main()
ans()

Submission status: Accepted

Solution code:
S = list(map(int, 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:
import sys

S = input()
center = len(S) // 2

if len(S) % 2 == 1:
    b = S[center]
    for i in range(1, center + 1):
        if S[center - i] != b or S[center + i] != b:
            print(center + i)
            sys.exit()
else:
    b = S[center - 1]
    for i in range(center):
        if S[center - i - 1] != b or S[center + i] != b:
            print(center + i)
            sys.exit()

print(len(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = N
i = 1
while i < N:
	if S[i-1] != S[i]:
		K = min(K, max(i, N-i))
	i += 1
print(K)

Submission status: Accepted

Solution code:
S=input()
if len(S)==1:
    print('1')
else:
    k=0
    L=[]
    while k < (len(S)-1):
        if S[k] != S[k+1]:
            L.append(max(k+1,len(S)-k-1))
            k += 1
        else:
            k += 1
    L.sort()
    if len(L)==0:
        print(len(S))
    else:
        print(L[0])

Submission status: Accepted

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

Submission status: Accepted

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

    dec = [0 for i in range(n)]
    inc = [0 for i in range(n)]
    ran = [0 for i in range(n)]

    for i in range(n):
        dec[i] = n-1-i
        inc[i] = i

    i = 0
    while i<n:
        if s[i] == '0':
            i += 1
        else:
            st = i
            while i<n and s[i]=='1':
                i += 1
            for j in range(st,i):
                ran[j] = i-st

    ans = n
    for i in range(n):
        v = max(dec[i],inc[i],ran[i])
        if s[i] == '1':
            ans = min(ans,v)
    return ans

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

    t = list(s[:])
    for i in range(n):
        if t[i] == '0':
            t[i] = '1'
        else:
            t[i] = '0'
    t = ''.join(t)

    return max(calc(s),calc(t))

if __name__ == '__main__':
    print(main())

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 = raw_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:
#abc083d

s=raw_input()
l=len(s)
res=l
for i in xrange(l-1):
 if s[i]!=s[i+1]:
  x=max(i+1,l-(i+1))
  res=min(res,x)
print res

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:
# -- coding: utf-8 --

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

print(k)

Submission status: Accepted

Solution code:
# D - Wide Flip
# coding: utf-8

N = raw_input()

if len(N)%2 == 0:
  result = len(N)/2
  center_pos = len(N)/2  
  center = N[center_pos]
  for i in range(len(N)/2):
    if N[center_pos+i] != center or N[center_pos-(i+1)] != center : break
    result += 1
else:
  result = (len(N)+1)/2
  center_pos = (len(N)-1)/2
  center = N[center_pos]
  for i in range((len(N)-1)/2):
    if N[center_pos+(i+1)] != center or N[center_pos-(i+1)] != center : break
    result += 1

print result

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

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

print(ans)

Submission status: Accepted

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

if ans == 100000000:
	ans = l
print(ans)

Submission status: Accepted

Solution code:
import math

s = input()
minpos = len(s)

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

        if pos < minpos:
            minpos = pos

print(minpos)

Submission status: Accepted

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

import sys

s = sys.stdin.readline().strip()
l = [_s is "1" for _s in list(s)]
l_r = l[::-1]
index = 0
for i, (c, n, c_r, n_r) in enumerate(
        zip(l[:len(s) // 2], l[1:len(s) // 2 + 1], l_r[:len(s) // 2], l_r[1:len(s) // 2 + 1])):
    if c ^ n or c_r ^ n_r:
        index = i + 1
print(len(s) - index)

Submission status: Accepted

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

import sys

s = sys.stdin.readline().strip()
check = [_s is "1" for _s in list(s)]
index = 0
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr ^ next:
        index = max(index, i + 1)
check = check[::-1]
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr ^ next:
        index = max(index, i + 1)
print(len(s) - index)

Submission status: Accepted

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

import sys

s = sys.stdin.readline().strip()
check = [_s is "1" for _s in list(s)]
index = 0
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr != next:
        index = i + 1
check = check[::-1]
for i, (curr, next) in enumerate(zip(check[:len(s) // 2], check[1:len(s) // 2 + 1])):
    if curr != next:
        index = max(index, i + 1)
print(len(s) - index)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))