AtCoder Beginner Contest 083 - Wide Flip

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-----
010

-----Sample Output-----
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.

Difficulty: MEDIUM

Starter code:

Solutions:
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
while l <= r:
	x = cums[r + 1] - cums[l]
	if x == r - l + 1 or x == 0:
		break
	ans -= 1
	l += 1
	r -= 1
print(ans)


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


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


S = input()
MIN = 10 ** 8
flag = 1
for i in range(len(S) - 1):
	if S[i] != S[i + 1]:
		flag = 0
		MIN = min(MIN, max(i + 1, len(S) - i - 1))
if flag:
	MIN = len(S)
print(MIN)


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)


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


s = input()
half = (len(s) - 1) // 2
ans = half + 1
c = s[half]
for (x, y) in zip(s[half + 1:], s[half - (len(s) % 2 == 1)::-1]):
	if x == c and y == c:
		ans += 1
	else:
		break
print(ans)


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)


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


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


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


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)


import numpy as np
S = str(input())
X = []
c = 1
for i in range(1, len(S)):
	if S[i] == S[i - 1]:
		c += 1
	elif S[i] != S[i - 1]:
		X += [c]
		c = 1
	if i == len(S) - 1:
		X += [c]
if len(S) == 1:
	X = [1]
if len(X) >= 3:
	X = np.cumsum(X)
	t = float('inf')
	for i in range(len(X) - 1):
		u = max(X[i], len(S) - X[i])
		t = min(u, t)
	answer = t
elif len(X) == 1:
	answer = X[0]
elif len(X) == 2:
	answer = max(X)
print(answer)


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)


from itertools import groupby
S = input()
N = len(S)
G = [len(list(l)) for (_, l) in groupby(S)]
A = 0
for g in G:
	A += g
	if A >= (N + 1) // 2:
		ans = min(A, N - A + g)
		print(ans)
		break


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


import sys

def main():
	s = input()
	l = len(s)
	if '0' not in s or '1' not in s:
		print(l)
	else:
		ans = 10 ** 6
		for i in range(l - 1):
			if s[i] != s[i + 1]:
				ans = min(ans, max(i + 1, l - i - 1))
		print(ans)

def __starting_point():
	main()
__starting_point()


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


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)


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)


S = input()
n = len(S)
if n % 2:
	m = n // 2
	t = S[m]
	for i in range(m):
		if S[m + i + 1] != t or S[m - i - 1] != t:
			a = m + i + 1
			break
	else:
		a = n
else:
	m = n // 2
	t = S[m]
	for i in range(m):
		if S[m + i] != t or S[m - i - 1] != t:
			a = m + i
			break
	else:
		a = n
print(a)


def main():
	S = input()
	A = []
	(i, t) = (1, S[0])
	for s in S[1:]:
		if s != t:
			A.append(i)
			i = 1
			t = s
		else:
			i += 1
	A.append(i)
	(m, l) = (len(S), 0)
	for a in A:
		t = max(l + a, len(S) - l - a)
		m = min(m, t)
		l += a
	return m
print(main())


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)


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


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)


S = input()
N = len(S)
if len(set(S)) == 1:
	print(N)
	exit()
K = (N + 1) // 2
X = set()
if N & 1:
	X = {S[K - 1]}
	l = K - 2
	r = K
else:
	X = set()
	l = K - 1
	r = K
while l:
	X.add(S[l])
	X.add(S[r])
	if len(X) > 1:
		break
	K += 1
	l -= 1
	r += 1
print(K)


from itertools import groupby, accumulate
S = list(input())
n = len(S)
s = list(accumulate([len(list(j)) for (i, j) in groupby(S)]))
s = [max(i, n - i) for i in s]
print(min(s))


I = input()
n = len(I)
left = 0
right = n - 1
block_left_index = 0
block_right_index = n
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)


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)


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)


S = input()
t = 10 ** 6
for i in range(1, len(S)):
	if S[i - 1] != S[i]:
		t = min(t, max(i, len(S) - i))
if t == 10 ** 6:
	print(len(S))
else:
	print(t)


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)


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


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)


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


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)


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)


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)


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


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)


S = list(input())

def check(x):
	for y in S[len(S) - x:x]:
		if y != S[len(S) - x]:
			break
	else:
		return True
	return False

def bisect(l, r):
	if r - l == 1:
		return l
	mid = (l + r) // 2
	if check(mid) == False:
		return bisect(l, mid)
	else:
		return bisect(mid, r)
print(bisect(0, len(S) + 1))


import sys

def solve(S: str):
	N = len(S)
	m = N
	for i in range(N - 1):
		if S[i] != S[i + 1]:
			m = min(m, max(N - (i + 1), i + 1))
	print(m)

def main():

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

def __starting_point():
	main()
__starting_point()


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)


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
m = n - 1
while len(res) > 1:
	resu = min(resu, max(res[0], m - res[0]))
	x = res.pop(1)
	res[0] = res[0] + x
print(resu)


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)


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


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
		tmp = max(left, right)
		max_ = min(max_, tmp)
print(max_)


s = list(str(input()))
n = len(s)
ans = 10 ** 10
for i in range(n - 1):
	if s[i] != s[i + 1]:
		ans = min(ans, max(i + 1, n - i - 1))
if ans == 10 ** 10:
	print(n)
else:
	print(ans)


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)


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)


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)


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)


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)


s = input()
cs = []
cnt = 1
pre = s[0]
for si in s[1:]:
	if si == pre:
		cnt += 1
	else:
		cs.append(cnt)
		pre = si
		cnt = 1
cs.append(cnt)
n = len(s)
ans1 = n
merge = 0
no_merge = n
for i in range(len(cs)):
	merge += cs[i]
	no_merge -= cs[i]
	tmp = max(merge, no_merge)
	ans1 = min(ans1, tmp)
cs.reverse()
ans2 = n
merge = 0
no_merge = n
for i in range(len(cs)):
	merge += cs[i]
	no_merge -= cs[i]
	tmp = max(merge, no_merge)
	ans2 = min(ans2, tmp)
print(max(ans1, ans2))


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)


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


S = input()
j = 0
m = S[0]
ls = []
for i in range(len(S)):
	if m != S[i]:
		ls += [i - j]
		j = i
		m = S[i]
ls += [len(S) - j]
N = len(ls)
if N < 3:
	print(max(ls))
else:
	ans = float('inf')
	sls = [ls[0]]
	for i in range(1, N):
		sls += [sls[-1] + ls[i]]
	for i in range(N - 1):
		ans = min(ans, max(sls[i], sls[-1] - sls[i]))
	print(ans)


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)


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


S = input()
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))
	return
lst = []
for i in range(len(boundary)):
	lst.append(max(boundary[i], len(S) - boundary[i]))
ans = min(lst)
print(ans)


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


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


s = input()
len_s = len(s)
ans = len_s // 2
center = ans
b = s[ans]
if len_s % 2:
	for i in range(center + 1):
		if s[center - i] == s[center + i] == b:
			ans += 1
		else:
			break
else:
	for i in range(center):
		if s[center - 1 - i] == s[center + i] == b:
			ans += 1
		else:
			break
print(ans)


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)


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)


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)


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)


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)


s = input()
l = len(s)
center = s[l // 2]
cnt = l % 2
for (e1, e2) in zip(s[:l // 2][::-1], s[l // 2 + l % 2:]):
	if center == e1 == e2:
		cnt += 2
	else:
		break
ans = (l + cnt) // 2
print(ans)


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


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


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


import sys
s = sys.stdin.readline().rstrip()
n = len(s)

def main():
	m = n // 2
	if n & 1:
		l = s[m::-1]
		r = s[m:]
	else:
		l = s[m - 1::-1]
		r = s[m:]
	base = l[0]
	cnt = m
	i = 0
	if n & 1:
		m += 1
	while i < m:
		if l[i] == r[i] == base:
			i += 1
			cnt += 1
		else:
			break
	return cnt

def __starting_point():
	ans = main()
	print(ans)
__starting_point()


s = list(input())
n = len(s)
if n % 2 == 0:
	for i in range(n // 2):
		a = s[n // 2]
		if s[n // 2 - 1 - i] != a or s[n // 2 + i] != a:
			print(n // 2 + i)
			return
else:
	for i in range(1, (n - 1) // 2 + 1):
		b = s[(n - 1) // 2]
		if s[(n - 1) // 2 - i] != b or s[(n - 1) // 2 + i] != b:
			print((n - 1) // 2 + i)
			return
print(n)


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)


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


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)


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)


def rle(s):
	before_c = s[0]
	ret = list()
	cnt = 0
	for c in s:
		if before_c == c:
			cnt += 1
		else:
			ret.append(cnt)
			before_c = c
			cnt = 1
	if cnt > 0:
		ret.append(cnt)
	return ret

def main():
	S = input()
	N = len(S)
	seq_cnt = rle(S)
	if len(seq_cnt) == 1:
		print(seq_cnt[0])
		return
	if len(seq_cnt) == 2:
		print(max(seq_cnt))
		return
	cumsum_seq_cnt = [0 for _ in range(len(seq_cnt))]
	rev_cumsum_seq_cnt = [0 for _ in range(len(seq_cnt))]
	cumsum_seq_cnt[0] = seq_cnt[0]
	rev_cumsum_seq_cnt[0] = seq_cnt[-1]
	for i in range(1, len(seq_cnt)):
		cumsum_seq_cnt[i] = cumsum_seq_cnt[i - 1] + seq_cnt[i]
		rev_cumsum_seq_cnt[i] = rev_cumsum_seq_cnt[i - 1] + seq_cnt[-1 - i]
	max_k = cumsum_seq_cnt[0]
	rev_max_k = rev_cumsum_seq_cnt[0]
	for i in range(1, len(seq_cnt)):
		k = cumsum_seq_cnt[i]
		if k <= N - cumsum_seq_cnt[i - 1]:
			max_k = k
		rev_k = rev_cumsum_seq_cnt[i]
		if rev_k <= N - rev_cumsum_seq_cnt[i - 1]:
			rev_max_k = rev_k
	print(max([max_k, rev_max_k]))

def __starting_point():
	main()
__starting_point()


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


s = input()
n = len(s)
ans = n
s1 = s.count('1')
i = 0
while s1 != 0 and s1 != n:
	s1 -= int(s[i]) + int(s[i + n - 1])
	if n == 1:
		s1 += int(s[i])
	n -= 2
	ans -= 1
	i += 1
print(ans)


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)


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)


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)


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


slist = list(map(int, list(input())))
len_s = len(slist)
min_answer = len_s
for i in range(1, len_s):
	if slist[i - 1] != slist[i]:
		min_answer = min(min_answer, max(i, len_s - i))
print(min_answer)


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)


S = [0] + list(map(int, list(input())))
N = len(S) - 1

def change(s, c):
	if c == 0:
		return s
	else:
		return 1 - s

def check(k):
	count = [0] * (N + 1)
	T = S.copy()
	for i in range(1, N + 1):
		c = count[i - 1]
		s = change(S[i], c)
		if i < N - k + 2:
			T[i] = 0
			if s == 1:
				count[i] = (c + 1) % 2
			else:
				count[i] = c
		else:
			T[i] = s
			count[i] = c
	n = 0
	for t in T[1:]:
		if t == 1:
			break
		n += 1
	return n >= k
left = 1
right = N
while left + 1 < right:
	mid = (left + right) // 2
	if check(mid):
		left = mid
	else:
		right = mid
if right == N and check(N):
	print(N)
else:
	print(left)


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)


S = input()
z = 0
o = 0
for i in S:
	if i == '0':
		z += 1
	else:
		o += 1
for i in range(len(S)):
	if o == 0 or z == 0:
		print(len(S) - i)
		break
	if S[i] == '0':
		z -= 1
	else:
		o -= 1
	if S[-1 - i] == '0':
		z -= 1
	else:
		o -= 1


s = input()
l = len(s)
ans = l
for (i, (e1, e2)) in enumerate(zip(s, s[1:]), 1):
	if e1 != e2:
		ans = min(ans, max(i, l - i))
print(ans)


s = input()
lns = len(s)
r = lns
for (i, (b, c)) in enumerate(zip(s, s[1:])):
	if b != c:
		r = min(r, max(i + 1, lns - i - 1))
print(r)


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


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


s = input()
n = len(s)
l = 0
r = n // 2 + 1
while r - l > 1:
	m = l + (r - l) // 2
	d = n // 2 - m
	if s[d:n - d].count('0') == 0 or s[d:n - d].count('1') == 0:
		l = m
	else:
		r = m
if n % 2 == 0:
	print(n // 2 + l)
else:
	print(n // 2 + l + 1)


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)


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


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)


S = input() + '#'
pressed = []
prev = S[0]
count = 0
for s in S:
	if s == prev:
		count += 1
	else:
		prev = s
		pressed.append(count)
		count = 1
left_cumsum = []
right_cumsum = []
cumsum = 0
for count in pressed:
	cumsum += count
	left_cumsum.append(cumsum)
cumsum = 0
for count in pressed[::-1]:
	cumsum += count
	right_cumsum.append(cumsum)
length = len(left_cumsum)
if length == 1:
	print(len(S) - 1)
	return
change_k = [0] * length
for idx in range(1, length):
	k = right_cumsum[-idx - 1]
	change_k[idx - 1] = k
for idx in range(1, length):
	k = left_cumsum[-idx - 1]
	change_k[-idx] = max(change_k[-idx], k)
ans1 = min(change_k[::2])
ans2 = min(change_k[1::2])
print(max(ans1, ans2))


from collections import deque
(x, y) = (deque(), deque())
s = deque(list(input()))
n = len(s)
m = s[n // 2]
ans = (n + 1) // 2
for _ in range((n + 1) // 2):
	x.appendleft(s.popleft())
for _ in range(n // 2):
	y.appendleft(s.pop())
if n % 2 == 1:
	x.popleft()
for i in range(n // 2):
	if x[i] == y[i] == m:
		ans += 1
	else:
		break
print(ans)


def main():
	S = input()
	r = len(S)
	if S.count('0') == r:
		return r
	if S.count('1') == r:
		return r
	N = len(S)
	one = S[0] == '1'
	c = 0
	for i in range(N):
		if S[i] == '1' and one or (S[i] == '0' and (not one)):
			continue
		r = min(r, max(i, N - i))
		one = S[i] == '1'
	return r
print(main())


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


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)


import sys
sys.setrecursionlimit(100000000)

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

def __starting_point():
	main()
__starting_point()


import math

def f(s):
	if len(s) % 2 == 0:
		p = len(s) // 2 - 1
	else:
		p = len(s) // 2
	q = p
	while q < len(s) and s[p] == s[q]:
		q += 1
	return q
s = input()
l = len(s)
ans = l
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		ans = min(ans, max(i + 1, l - i - 1))
print(ans)


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)


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)


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)


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)


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)


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)


s = list(input())
ans = float('INF')
if len(s) == 1:
	print(1)
	exit()
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		c = max(i + 1, len(s) - i - 1)
		ans = min(ans, c)
if ans == float('INF'):
	print(len(s))
else:
	print(ans)


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)


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)


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


import io
import sys
import math
data = input()
n = len(data)
ans = n
for i in range(n - 1):
	if data[i] != data[i + 1]:
		ans = min(ans, max(i + 1, n - i - 1))
print(ans)


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)


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 list(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):
	if not S[i] == S[N - 1 - i] == S[i - 1]:
		break
	ans += 1
print(ans)


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


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)


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


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


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


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)


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


s = input()
n = len(s)
k = 10 ** 9
if not '1' in s:
	print(n)
elif not '0' in s:
	print(n)
else:
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			k = min(k, max(i + 1, n - (i + 1)))
	if k > n:
		print(n)
	else:
		print(k)


S = str(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)


s = list(input())
l = len(s)
if l % 2 == 0:
	for i in range(l // 2):
		a = s[l // 2]
		if s[l // 2 - 1 - i] != a or s[l // 2 + i] != a:
			print(l // 2 + i)
			exit()
else:
	for i in range(1, (l - 1) // 2 + 1):
		a = s[(l - 1) // 2]
		if s[(l - 1) // 2 - i] != a or s[(l - 1) // 2 + i] != a:
			print((l - 1) // 2 + i)
			exit()
print(l)


import math

def f(s):
	if len(s) % 2 == 0:
		p = len(s) // 2 - 1
	else:
		p = len(s) // 2
	q = p
	while q < len(s) and s[p] == s[q]:
		q += 1
	return q
s = input()
print(min(f(s), f(s[::-1])))


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)


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


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)


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)


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


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)


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


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)
print(solve(input()))


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


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)


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


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)


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


s = input()
i_flips = []
i = 0
for j in range(1, len(s)):
	if s[j] != s[i]:
		i_flips.append(j)
		i = j
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)


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)


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)


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)


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)


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


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


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)


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)


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)


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


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)


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)


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)


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)


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


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


s = input()
if len(s) % 2 == 0:
	number = s[len(s) // 2]
	other = s[len(s) // 2 - 1]
	p = len(s) // 2
	cnt = 0
	if number == other:
		cnt += 1
		for i in range(1, p):
			if s[p + i] == s[p - 1 - i] == number:
				cnt += 1
			else:
				break
	print(p + cnt)
else:
	number = s[len(s) // 2]
	cnt = 0
	p = len(s) // 2
	for i in range(1, len(s) // 2 + 1):
		if s[p - i] == s[p + i] == number:
			cnt += 1
		else:
			break
	print(p + 1 + cnt)


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)


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)


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)


from sys import exit
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)


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)


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


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


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)


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


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)


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


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