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

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
S = input()

len_S = len(S)
if len_S % 2 == 0:
    half_len = int(len_S / 2)
else:
    half_len = int(len_S / 2) + 1

idx = None
target = None

for i in range(half_len):
    if S[i] == S[-i-1]:
        if target == None:
            target = S[i]
            idx = i
        else:
            if S[i] != target:
                target = S[i]
                idx = i
            else:
                continue
    else:
        target = None
        idx = None

if idx != None:
    print(len_S - idx)
else:
    print(half_len)

Solution (Python):
import sys

change = False
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)

        
        

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

Solution (Python):
import sys

change = False
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)

        
        

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

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

Solution (Python):
l = list(raw_input())

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
else:
    mx = max(mx, min(i+1, len(l)-x))
print mx

Solution (Python):
import re

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

print(min)

Solution (Python):

S = input()
n = len(S)
ans = n // 2
pv = S[n // 2]
for i in range(n // 2, n):
    new = [S[n - i - 1], S[i]]
    if set(new) != set(pv):
        break
    ans += 1
print(ans)

Solution (Python):

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

Solution (Python):
S = input().strip()

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

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

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

Solution (Python):
import math
s = input()
count = 1
slist = list(s)
strlen = len(s)
count = None
if strlen % 2 == 1:
    count = math.ceil(strlen/2)
    center = slist[math.floor(strlen/2)]
    for i in range(math.floor(strlen/2)):
        if center == slist[math.floor(strlen/2)- i - 1] and center == slist[math.ceil(strlen/2)+i]:
            count +=1
        else:
            break
else:
    count = strlen / 2
    center = slist[int(strlen/2)]
    for i in range(int(strlen/2)):
        if center == slist[int(strlen/2)+i] and center == slist[int(strlen/2) - 1 - i]:
            count += 1
        else:
            break
print(int(count))

Solution (Python):
S = input()

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)

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

Solution (Python):
S = input()

zero = "00"

one = "11"

if len(S) % 2 == 0:
	
	Ans = int(len(S) / 2 )
	flont = Ans - 1
	back = Ans + 1
	while (1):
		if S[flont:back] == zero:
			zero += "00"
			flont -= 1
			back += 1
			Ans += 1
			continue
		if S[flont:back] == one:
			one += "11"
			flont -= 1
			back += 1
			Ans += 1
			continue
		else:
			break

if len(S) % 2 == 1:
	zero = "0"
	one = "1"
	Ans = int(len(S) / 2 + 0.5)
	flont = Ans - 1
	back = Ans
	while(1):
		if S[flont:back] == zero:
			zero += "00"
			flont -= 1
			back += 1
			Ans += 1
			continue
		if S[flont:back] == one:
			one += "11"
			flont -= 1
			back += 1
			Ans += 1
			continue
		else:
			Ans -= 1
			break	

print(Ans)

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

Solution (Python):
s = input()
l = len(s)
ans = l//2
if l % 2 == 0:
    a,b = l//2 - 1, l//2
else:
    a,b = l//2, l//2

t = s[a:b+1]
while t == '1' * len(t) or t == '0' * len(t):
    ans += 1
    a -= 1
    b += 1
    if a < 0 or b >= l:break
    t = s[a:b+1]

print(ans)

Solution (Python):
def d_WideFlip(S):
    n = len(S)
    T = []  
    for k in range(n - 1):
        if S[k] != S[k + 1]:
            T.append(max(k + 1, n - (k + 1)))  
    if len(T) > 0:
        return min(T)
    else:
        return n  

S = input()
print(d_WideFlip(S))

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

Solution (Python):
if __name__=="__main__":
    l = list(input())
    N = len(l)
    results = []
    for i in range(0,N-1):
        if not l[i]==l[i+1]:
            results.append(max(i+1,N-i-1))
    if len(results):
        print(min(results))
    else:
        print(N)

Solution (Python):
import math
S = input()
L = S[:math.ceil(len(S)/2)]
R = S[len(S)//2:]

if L[-1] == R[0]:
  j = 1
  i = 1
  while i < len(L):
    if R[0] == R[i] and L[-i-1] == R[i]:
      
      
      j += 1
      
    else:
      break
    i+=1
    
else:
  j = 0 
  

print(math.floor(len(S)/2) + j)

Solution (Python):
import sys

def solve1(s):
    n = len(s)
    i = 0
    while i <= n // 2:
        if s[n // 2] != s[n // 2 - i]:
            break
        if s[(n - 1) // 2] != s[(n - 1) // 2 + i]:
            break
        i += 1
    return (n - 1) // 2 + i


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

Solution (Python):
s = raw_input()

n = ans = len(s)

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

print ans

Solution (Python):
s = raw_input()
n = len(s)
if n == 1:
    print 1
    exit()
if not n & 1:
    l = n / 2 - 1
    r = n / 2
    res = n / 2
    while r < n and l >= 0 and s[l] == s[r]:
        l -= 1
        r += 1
        res += 1
    print res
else:
    l = n / 2 - 1
    r = n / 2 + 1
    res = n / 2 + 1
    if s[n / 2] != s[l] or s[n / 2] != s[r]:
        print res
    else:
        while r < n and l >= 0 and s[l] == s[r]:
            l -= 1
            r += 1
            res += 1
        print res

Solution (Python):
A=list(map(int,list(input())))
L = len(A)
num = L
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
    pre = A[i]
print(num)

Solution (Python):
import sys
l = list(raw_input())
if (not "0" in l) or (not "1" in l):
    print len(l)
    sys.exit()

s = l[0]
f = False
mx = 0
x = 0
for i, n in enumerate(l):
    if not n == s:
        mx = max(mx, min(i, len(l)-x))
        x = i
        s = n
mx = max(mx, min(i, len(l)-x))
print mx

Solution (Python):
S = input()
n = len(S)
j = 0
for i in range(1, n):
    if S[i - 1] != S[i]:
        if abs(n - 2 * i) < abs(n - 2 * j):
            j = i
print(max([j, n - j]))

Solution (Python):
S =str(input())
if len(S) % 2 == 1:
    a = 1
    b = int((len(S) - 1) / 2)
    while True:
        if b - a < 0:
            break
        if S[b] == S[b + a] and S[b] == S[b - a]:
            a = a + 1
        else:
            break
    c = a + b
    print(c)
else:
    d = 0
    e = int(len(S) / 2 - 1)
    f = S[e]
    if S[e + 1] == f:
        d = d + 1
    while True:
        if e - d < 0:
            break
        if S[e - d] == f and S[e + d + 1] == f:
            d = d + 1
        else:
            break
    g = d + e + 1
    print(g)

Solution (Python):


S=[int(i) for i in input()]
L = len(S)


if L%2 == 1:
    mid = (L-1)//2
    midnum = S[mid]
    a = 0
    while mid-a != -1 and S[mid-a] == S[mid+a] == midnum:
        a += 1
    print(mid+a)
else:
    mid = (L-1)//2
    midnum1 = S[mid]
    midnum2 = S[mid+1]
    a = 0
    while mid-a != -1 and S[mid-a] == S[mid+1+a] == midnum1 == midnum2:
        a += 1
    print(mid+a+1)

Solution (Python):


s = input()
l = []
r = []
len_s = len(s)
if(len_s==1):
    print(1)
else:
    for i in range(len_s-1):
        if(s[i]!=s[i+1]):
            l.append(i+1)
            r.append(len_s-i-1)
    if(len(l)==0):
        print(len_s)
    else:
        half = len(l)
        l.extend(r)
        l.sort()
        print(len_s-l[half-1])

Solution (Python):
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 - 1 - i] != b or S[center + i] != b:
            print(center + i)
            sys.exit()
print(len(S))