Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. 

Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.

Before assembling the zebra Grisha can make the following operation $0$ or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order "bwbbw" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain "wbwbb".

Determine the maximum possible length of the zebra that Grisha can produce.


-----Input-----

The only line contains a string $s$ ($1 \le |s| \le 10^5$, where $|s|$ denotes the length of the string $s$) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.


-----Output-----

Print a single integer — the maximum possible zebra length.


-----Examples-----
Input
bwwwbwwbw

Output
5

Input
bwwbwwb

Output
3



-----Note-----

In the first example one of the possible sequence of operations is bwwwbww|bw $\to$ w|wbwwwbwb $\to$ wbwbwwwbw, that gives the answer equal to $5$.

In the second example no operation can increase the answer.

Difficulty: MEDIUM_HARD
Tags: Implementation

Constructive algorithms
Expected Time Complexity: O(N)

Starter code:

Solutions:
zebra = input()
length = len(zebra)

def checkLongest(zebra):
	longest = 0
	curr = 0
	prev = 0
	for i in zebra:
		if ord(i) != prev:
			curr += 1
		else:
			if curr > longest:
				longest = curr
			curr = 1
		prev = ord(i)
	if curr > longest:
		longest = curr
	return longest

def finish(zebra, longest):
	temp = checkLongest(zebra)
	if temp > longest:
		return temp
	else:
		return longest

def flip(string):
	start = string[0]
	prev = start
	for i in range(1, length):
		if string[i] == prev:
			if start != string[length - 1]:
				string = string[0:i][::-1] + string[:i - 1:-1]
				return flip(string)
			else:
				return finish(string, longest)
		prev = string[i]
longest = checkLongest(zebra)
if longest == length:
	print(longest)
	exit()
if longest == length - 1:
	if zebra[0] == zebra[length - 1]:
		print(longest)
		exit()
	else:
		print(longest + 1)
		exit()
print(flip(zebra))


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def toogle(char):
	if char == 'b':
		return 'w'
	else:
		return 'b'

def main():
	string = input().strip()
	n = len(string)
	new = string + string
	ans = 1
	temp = 1
	for i in range(2 * n):
		if new[i] != new[i - 1]:
			temp += 1
		else:
			ans = max(ans, temp)
			temp = 1
	ans = max(ans, temp)
	print(min(ans, n))
main()


s = input() * 2
m = 1
n = 1
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		n += 1
	else:
		if n > m:
			m = n
		n = 1
if n > m:
	m = n
print(min(len(s) // 2, m))


a = input()
a += a
n = len(a)
ans = 1
s = 1
for i in range(n):
	if a[i - 1] != a[i]:
		s += 1
	else:
		if s > ans:
			ans = s
		s = 1
	if s > n // 2:
		s = n // 2
		break
if s > ans:
	ans = s
print(ans)


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

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

def main():
	s = input()
	st = s[0]
	en = s[len(s) - 2]
	preflen = 1
	suflen = 1
	lens = []
	c = 1
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1]:
			c += 1
		else:
			lens.append(c)
			c = 1
	if c != 1:
		lens.append(c)
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1]:
			preflen += 1
		else:
			break
	for i in range(len(s) - 2, 0, -1):
		if s[i] != s[i - 1]:
			suflen += 1
		else:
			break
	if preflen == len(s) - 1 or st == en:
		if len(s) - 1 > 1:
			print(max(lens))
		else:
			print(1)
	else:
		print(max(preflen + suflen, max(lens)))
	return
main()


def main():
	s = input()
	n = len(s)
	k = 1
	mk = 1
	if n == 1:
		print(1)
		return
	for i in range(1, n):
		if s[i] == s[i - 1]:
			mk = max(mk, k)
			k = 1
		else:
			k += 1
	mk = max(mk, k)
	if s[0] != s[-1] and mk != n:
		mk1 = 1
		for i in range(1, n):
			if s[i] == s[i - 1]:
				break
			else:
				mk1 += 1
		mk2 = 1
		for i in range(n - 2, -1, -1):
			if s[i] == s[i + 1]:
				break
			else:
				mk2 += 1
		mk = max(mk, mk1 + mk2)
	print(mk)
	return
main()


s = list(input())
u = []
n = len(s)
k = 1
for i in range(1, n):
	if s[i] != s[i - 1]:
		k += 1
	else:
		u.append(k)
		k = 1
u.append(k)
if s[0] == s[-1] or len(u) == 1:
	print(max(u))
else:
	print(max(max(u), u[0] + u[-1]))


def cl(s):
	l = [s[0]]
	mx = []
	c = 1
	for i in s[1:]:
		if i != l[-1]:
			c += 1
			l.append(i)
		else:
			mx.append(c)
			c = 1
			l = [i]
	mx.append(c)
	return max(mx)
sl = [i for i in input()]
ls = len(sl)
if ls == 1:
	print(1)
	exit(0)
if ls == 2:
	if sl[0] != sl[-1]:
		print(2)
	else:
		print(0)
	exit(0)
if cl(sl) == ls:
	print(ls)
	exit(0)
t = []
while 1:
	x = sl.pop(0)
	sl.append(x)
	if sl[0] == sl[-1]:
		t = list(sl)
		break
print(cl(t))


s = input()
s += s
(res, sofar) = (1, 1)
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		sofar = 1
	else:
		sofar += 1
	res = max(res, sofar)
print(min(res, len(s) // 2))


s = input()
n = len(s)
ar = [i for i in range(n) if s[i] == s[(i - 1) % n]]
if len(ar) > 0:
	ar.append(ar[0] + n)
else:
	print(n)
	exit()
best = 0
for i in range(len(ar)):
	best = max(best, ar[(i + 1) % len(ar)] - ar[i])
print(best)


s = input()
i = 0
j = len(s) - 1
c = 1
while i + 1 < len(s) and s[i] != s[i + 1]:
	c += 1
	i += 1
if i + 1 < len(s) and s[0] != s[len(s) - 1]:
	i = 0
	s = s[::-1]
	while i + 1 < len(s) and s[i] != s[i + 1]:
		c += 1
		i += 1
	c += 1
c2 = 1
c2_max = 0
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		c2 += 1
	else:
		if c2 > c2_max:
			c2_max = c2
		c2 = 1
if c2 > c2_max:
	c2_max = c2
print(max(c, c2_max))


s = input()
max_stripes = 1
cur_stripes = 1
i = 0
while i < len(s) - 1:
	if s[i] != s[i + 1]:
		cur_stripes += 1
	else:
		if cur_stripes > max_stripes:
			max_stripes = cur_stripes
		cur_stripes = 1
	i += 1
if cur_stripes > max_stripes:
	max_stripes = cur_stripes
if s[0] != s[-1]:
	stripes = 1
	i = 0
	while i < len(s) - 1 and s[i] != s[i + 1]:
		i += 1
		stripes += 1
	if stripes != len(s):
		stripes += 1
		i = len(s) - 1
		while s[i] != s[i - 1]:
			i -= 1
			stripes += 1
	max_stripes = max(max_stripes, stripes)
print(max_stripes)


def count(s, t):
	count = 1
	z = 0
	for i in range(t - 1):
		if s[i] != s[i + 1]:
			count += 1
		else:
			z = max(z, count)
			count = 1
	z = max(z, count)
	return z
s = str(input())
t = len(s)
a = s[::-1]
z = count(s, t)
z1 = count(a, t)
if z == t:
	print(z)
elif s[0] == s[t - 1]:
	print(max(z, z1))
else:
	c = 1
	d = 1
	for i in range(t - 1):
		if s[i] != s[i + 1]:
			c += 1
		else:
			break
	for j in range(t - 1):
		if a[j] != a[j + 1]:
			d += 1
		else:
			break
	print(max(z, z1, c + d))


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
s = list(input())
n = len(s)
for i in range(0, n - 1):
	if s[i] == s[i + 1] and s[0] != s[-1]:
		s1 = s[0:i + 1][::-1]
		s2 = s[i + 1:][::-1]
		s = s1 + s2
maxcnt = -1
cnt = 1
for i in range(n - 1):
	if s[i] != s[i + 1]:
		cnt += 1
	else:
		maxcnt = max(maxcnt, cnt)
		cnt = 1
maxcnt = max(maxcnt, cnt)
print(maxcnt)


def per(c):
	if c == 'w':
		a = 0
	else:
		a = 1
	return a
s = input()
l = []
a = 1
first = per(s[0])
last = per(s[-1])
for i in range(1, len(s)):
	if per(s[i - 1]) + per(s[i]) == 1:
		a += 1
	else:
		l.append(a)
		a = 1
		i += 1
l.append(a)
if first + last == 1 and len(l) != 1:
	l.append(l[0] + l[-1])
print(max(l))


s = input()
n = len(s)
rec = []
pre = s[0]
prei = 0
for i in range(1, n):
	if pre != s[i]:
		pre = s[i]
		continue
	else:
		rec.append(s[prei:i])
		pre = s[i]
		prei = i
rec.append(s[prei:])
num = 0
for i in rec:
	num = max(num, len(i))
if len(rec) >= 2:
	if rec[0][0] != rec[-1][-1]:
		num = max(num, len(rec[0] + rec[-1]))
print(num)


s = input()
n = len(s)
if n == 1:
	print(1)
elif n == 2:
	if s == 'bw' or s == 'wb':
		print(2)
	else:
		print(-1)
else:
	ans = 1
	maxans = -1
	for i in range(1, n + n + 1):
		if s[(i - 1) % n] == 'b' and s[i % n] == 'w':
			ans += 1
		elif s[(i - 1) % n] == 'w' and s[i % n] == 'b':
			ans += 1
		else:
			maxans = max(maxans, ans)
			ans = 1
	if maxans == -1:
		maxans = ans // 2
	print(maxans)


s = input().strip()
n = len(s)
max_l = 1
cur_l = 1
last_c = s[0]
for i in range(1, n * 2):
	cur_c = s[i % n]
	if last_c != cur_c:
		cur_l += 1
		max_l = max(max_l, cur_l)
		if cur_l == n:
			break
	else:
		cur_l = 1
	last_c = cur_c
print(max_l)


s = input()
last = s[0]
count = 1
best = 1
for i in range(1, len(s) * 2):
	if last != s[i % len(s)]:
		count += 1
		best = max(best, count)
		last = s[i % len(s)]
	else:
		count = 1
print(min(best, len(s)))


def ii():
	return int(input())

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

def li():
	return list(mi())
s = input().strip()
n = len(s)
s += s
p = ans = 1
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		p = 1
	else:
		p += 1
		ans = max(ans, p)
ans = min(ans, n)
print(ans)


s = input()
s *= 2
(prv, res, cnt) = ('$', 0, 0)
for i in s:
	if i != prv:
		cnt += 1
	else:
		cnt = 1
	prv = i
	res = max(res, cnt)
print(min(len(s) // 2, res))


word = input()
maximum = 0
prev = '-'
curlen = 0
for i in word:
	if prev == i:
		maximum = max(maximum, curlen)
		curlen = 1
	else:
		curlen += 1
		prev = i
maximum = max(maximum, curlen)
start = word[0]
left = 1
i = 1
while True:
	if left == len(word):
		break
	if word[i] != start:
		left += 1
		start = word[i]
		i += 1
	else:
		break
start = word[-1]
right = 1
i = len(word) - 2
while True:
	if right == len(word):
		break
	if word[i] != start:
		right += 1
		start = word[i]
		i -= 1
	else:
		break
if len(word) == 1:
	print(1)
elif word[0] != word[-1]:
	poss = left + right
	if poss > len(word):
		print(len(word))
	else:
		print(max(poss, maximum))
else:
	print(maximum)


string = input()
string += string
ans = 0
sm = 0
for i in range(len(string) - 1):
	if string[i] != string[i - 1]:
		sm += 1
		ans = max(ans, sm)
	else:
		sm = 0
print(min(ans + 1, len(string) // 2))


s = input()
l = len(s)
s = s * 2
(c, ma) = (1, 1)
f = 0
for i in range(2 * l - 1):
	if s[i] == s[i + 1]:
		f = 1
		if c > ma:
			ma = c
		c = 0
	c += 1
if f == 0:
	ma = c
if ma > l:
	print(l)
else:
	print(ma)


s = input() * 2
l = len(s)
i = 0
ans = 1

def check():
	global i
	res = 1
	last = s[i]
	stop = min(l, i + l // 2)
	i += 1
	while i < stop:
		if s[i] == last:
			break
		else:
			res += 1
			last = s[i]
			i += 1
	return res
while i < l // 2:
	ans = max(check(), ans)
print(ans)


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


import sys, os, io
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from sys import stdin
import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
for _ in range(t):
	s = si()
	s = s * 3
	m = 0
	c = 1
	for i in range(1, len(s)):
		if s[i] != s[i - 1]:
			c += 1
		else:
			m = max(m, c)
			c = 1
	m = max(m, c)
	m = min(m, len(s) // 3)
	print(m)


def abcd(str):
	str = str * 2
	previous = 't'
	ans = 0
	count = 0
	for i in str:
		if i != previous:
			previous = i
			count += 1
		else:
			count = 1
		ans = max(ans, count)
	m = min(len(str) // 2, ans)
	return m
x = input()
t = abcd(x)
print(t)


s = input()
c = 1
mx = 1
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		c += 1
	elif s[0] != s[-1]:
		s = s[:i + 1][::-1] + s[i + 1:][::-1]
		c += 1
	else:
		if c > mx:
			mx = c
		c = 1
print(max(mx, c))


s = input()
tot = len(s)
s = s + s
maxVal = 1
currVal = 1
curr = s[0]
for i in range(1, len(s)):
	if s[i] == curr:
		currVal = 1
	else:
		currVal += 1
		curr = s[i]
		if maxVal < currVal:
			maxVal = currVal
if maxVal > tot:
	maxVal = tot
print(maxVal)


import sys
input = sys.stdin.readline
s = [i for i in input() if i != '\n']

def checker(s):
	(forw, back) = (0, 0)
	for i in range(1, len(s)):
		if s[i - 1] != s[i]:
			forw += 1
		else:
			break
	for i in range(len(s) - 1, 0, -1):
		if s[i] != s[i - 1]:
			back += 1
		else:
			break
	return forw + back + 2
(count, store) = (0, [])
for i in range(1, len(s)):
	if s[i - 1] != s[i]:
		count += 1
	elif count > 0:
		store.append(count + 1)
		count = 0
if count > 0:
	store.append(count + 1)
if s[0] != s[-1]:
	ans = checker(s)
	print(min(len(s), max(ans, max(store))))
elif len(store) == 0:
	print(1)
else:
	print(max(store))


s = input()
s += s
(cnt, res, prev) = (1, 1, s[0])
for i in range(1, len(s)):
	if s[i] is not prev:
		cnt += 1
	else:
		res = max(res, cnt)
		cnt = 1
	prev = s[i]
res = max(res, cnt)
print(min(res, len(s) // 2))


def calc(s):
	curr = s[0]
	count = 1
	for i in range(1, len(s)):
		if curr == s[i]:
			return count
		else:
			count += 1
			curr = s[i]
	return count
s = input()
f = calc(s)
b = calc(s[::-1])
c = 0
x = s[0]
i = 1
l = 0
count = 1
while i < len(s):
	if s[i] != x:
		count += 1
	else:
		l = max(l, count)
		count = 1
	x = s[i]
	i += 1
if f + b <= len(s) and s[0] != s[-1]:
	c = f + b
print(max(c, f, b, l))


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


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


def mni(i, n):
	return i + 1

def check(s, b):
	res = 1
	i = b
	cur = s[i]
	i = (i + 1) % len(s)
	while i != b:
		if cur != s[i]:
			res += 1
			cur = s[i]
			i = (i + 1) % len(s)
		else:
			break
	return res
S = input()
N = len(S)
if S == 1:
	ans = 1
else:
	ans = 0
	for i in range(len(S)):
		if i == 0 or S[i] == S[(i - 1 + N) % N]:
			ans = max(ans, check(S, i))
print(ans)


def zebra_len(zebra):
	l = 1
	c = 0
	p = 'x'
	for z in zebra:
		if p == 'w' and z == 'b' or (p == 'b' and z == 'w'):
			c += 1
			l = max(l, c)
		else:
			c = 1
		p = z
	return l

class CodeforcesTask1025CSolution:

	def __init__(self):
		self.result = ''
		self.zebra = ''

	def read_input(self):
		self.zebra = input()

	def process_task(self):
		self.result = str(min(len(self.zebra), zebra_len(self.zebra * 2)))

	def get_result(self):
		return self.result
Solution = CodeforcesTask1025CSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def main():
	s = list(input()) * 2
	ans = 0
	k = 1
	for i in range(len(s) - 1):
		if s[i] == 'b' and s[i + 1] == 'b' or (s[i] == 'w' and s[i + 1] == 'w'):
			ans = max(ans, k)
			k = 1
		else:
			k += 1
	ans = max(ans, k)
	print(min(ans, len(s) // 2))
main()


r = input()
l = len(r)
ans1 = 0
prev = r[0]
ans2 = 1
for i in range(1, l):
	if r[i] != prev:
		ans2 = ans2 + 1
	else:
		ans1 = max(ans1, ans2)
		ans2 = 1
	prev = r[i]
ans1 = max(ans1, ans2)
ans3 = 1
prev = r[0]
for i in range(1, l):
	if r[i] == prev:
		break
	ans3 = ans3 + 1
	prev = r[i]
ans4 = 1
prev = r[-1]
for i in range(l - 2, 0, -1):
	if r[i] == prev:
		break
	ans4 = ans4 + 1
	prev = r[i]
ans5 = ans3 + ans4
if r[0] == r[-1]:
	print(ans1)
else:
	print(min(l, max(ans1, ans5)))


import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
s = input()
pp = s + s
ll = 0
i = 0
zz = 0
while i < len(pp) - 1:
	if pp[i] != pp[i + 1]:
		zz += 1
		i += 1
	else:
		ll = max(zz, ll)
		zz = 0
		i += 1
ll = max(zz, ll)
if ll > len(s):
	print(len(s))
else:
	print(ll + 1)


import sys
import math
S = input()
S = S + S
result = [1]
for i in range(1, len(S)):
	if S[i] != S[i - 1]:
		result.append(result[i - 1] + 1)
	else:
		result.append(1)
print(int(min(len(S) / 2, max(result))))


s = str(input())
fans = 1
first = s[0]
last = s[-1]
i = 0
j = len(s) - 1
tempans = 1
turns = 0
counter = len(s) - 1
while i < counter and i < j and (i < len(s) - 1):
	if turns % 2 == 0:
		if s[i] != s[i + 1]:
			tempans += 1
			fans = max(tempans, fans)
			i += 1
		elif first == last:
			tempans = 1
			i += 1
		else:
			first = s[i]
			last = s[i + 1]
			tempans += 1
			fans = max(tempans, fans)
			i += 1
			turns += 1
			j = counter
	elif s[j] != s[j - 1]:
		tempans += 1
		fans = max(tempans, fans)
		j -= 1
		counter -= 1
	elif first == last:
		tempans = 1
		j -= 1
		counter -= 1
	else:
		first = s[j]
		last = s[j - 1]
		tempans += 1
		fans = max(tempans, fans)
		j -= 1
		turns += 1
		counter = j
i = len(s) - 1
j = 0
counter = 0
first = s[0]
last = s[-1]
turns = 0
tempans = 1
while i > counter and i > j and (i > 0):
	if turns % 2 == 0:
		if s[i] != s[i - 1]:
			tempans += 1
			fans = max(fans, tempans)
			i -= 1
		elif first == last:
			tempans = 1
			i -= 1
		else:
			first = s[i - 1]
			last = s[i]
			tempans += 1
			fans = max(fans, tempans)
			i -= 1
			turns += 1
			j = counter
	elif s[j] != s[j + 1]:
		tempans += 1
		fans = max(tempans, fans)
		j += 1
		counter += 1
	elif first == last:
		tempans = 1
		j += 1
		counter += 1
	else:
		first = s[j]
		last = s[j + 1]
		tempans += 1
		fans = max(tempans, fans)
		j += 1
		turns += 1
		counter = j
print(fans)


s = input()
res = 1
ans = -10000
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		res += 1
	else:
		ans = max(ans, res)
		res = 1
ans = max(ans, res)
res1 = 1
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		res1 += 1
	else:
		break
res2 = 1
for i in range(len(s) - 2, res1 - 1, -1):
	if s[i] != s[i + 1]:
		res2 += 1
	else:
		break
if len(s) == 1:
	print(1)
elif s[0] == s[-1] or res1 + res2 > len(s):
	print(ans)
else:
	print(max(ans, res1 + res2))


s = str(input())
m = 0
n = len(s)
a = s[0]
s += s
t = 0
for i in range(n * 2 - 1):
	if s[i + 1] == a:
		if t > m:
			m = t
		t = 0
	else:
		t += 1
	if t == n:
		m = t
	a = s[i + 1]
print(m + 1) if m < n else print(n)


s = input().strip()
n = len(s)
a = ''
for i in range(n):
	if i == 0:
		l = n - 1
	else:
		l = i - 1
	if s[l] != s[i]:
		a += s[i]
	else:
		break
s += a
r = 1
sum = 1
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		sum += 1
	else:
		sum = 1
	r = max(r, sum)
print(min(r, n))


from collections import deque
s2 = deque(input())
s4 = s2.copy()
s1 = deque()
s1.append(s2[0])
s2.popleft()
t = True
while len(s2) > 0:
	if t:
		if s1[-1] != s2[0]:
			s1.append(s2[0])
			s2.popleft()
		elif s1[0] != s2[-1]:
			t = False
		else:
			s1 += s2
			break
	elif s1[0] != s2[-1]:
		s1.appendleft(s2[-1])
		s2.pop()
	elif s1[-1] != s2[0]:
		t = True
	else:
		s1 += s2
		break
ans = 1
x = 1
for i in range(1, len(s1)):
	if s1[i] != s1[i - 1]:
		x += 1
	else:
		ans = max(ans, x)
		x = 1
ans = max(ans, x)
s2 = s4.copy()
s2.reverse()
s1 = deque()
s1.append(s2[0])
s2.popleft()
t = True
while len(s2) > 0:
	if t:
		if s1[-1] != s2[0]:
			s1.append(s2[0])
			s2.popleft()
		elif s1[0] != s2[-1]:
			t = False
		else:
			s1 += s2
			break
	elif s1[0] != s2[-1]:
		s1.appendleft(s2[-1])
		s2.pop()
	elif s1[-1] != s2[0]:
		t = True
	else:
		s1 += s2
		break
ans1 = 1
x = 1
for i in range(1, len(s1)):
	if s1[i] != s1[i - 1]:
		x += 1
	else:
		ans1 = max(ans1, x)
		x = 1
ans1 = max(ans1, x)
print(max(ans1, ans))


s = input()
ans = 1
m = [1] * len(s)
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		m[i] = m[i - 1] + 1
		if m[i] > ans:
			ans = m[i]
	else:
		m[i] = 1
if s[0] != s[-1]:
	if m[-1] == len(s):
		print(m[-1])
		return
	else:
		for i in range(len(s)):
			if s[i] != s[i - 1]:
				m[i] = m[i - 1] + 1
				if m[i] > ans:
					ans = m[i]
			else:
				break
		print(ans)
		return
else:
	print(ans)


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	s = input()
	n = len(s)
	s += s
	ct = 1
	ans = 1
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			ct += 1
			ans = max(ct, ans)
		else:
			ct = 1
	print(min(ans, n))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


a = input()
l = []
s = len(a)
for i in range(s):
	l.append(a[i])
if l[0] != l[-1]:
	w = l[-1]
	for i in range(s - 2, -1, -1):
		if l[i] == w:
			break
		w = l[i]
	if i != 0:
		li = []
		v = i
		for i in range(v, -1, -1):
			li.append(l[i])
		for i in range(s - 1, v, -1):
			li.append(l[i])
		si = 1
		su = 0
		for i in range(1, s):
			if li[i - 1] != li[i]:
				si = si + 1
			else:
				su = max(si, su)
				si = 1
		print(max(su, si))
	else:
		si = 1
		su = 0
		for i in range(1, s):
			if l[i - 1] != l[i]:
				si = si + 1
			else:
				su = max(si, su)
				si = 1
		print(max(su, si))
else:
	si = 1
	su = 0
	for i in range(1, s):
		if l[i - 1] != l[i]:
			si = si + 1
		else:
			su = max(si, su)
			si = 1
	print(max(su, si))


a = input()
a = a + a
ma = 1
last = 'x'
pos = 0
cur = 0
while pos < len(a):
	if a[pos] != last:
		cur += 1
		ma = max(ma, cur)
	else:
		cur = 1
	last = a[pos]
	pos += 1
print(min(ma, len(a) // 2))


import sys
input = sys.stdin.readline
s = list(input().rstrip())
n = len(s)
s.extend(s)
cnt = 0
c = 1
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		c += 1
	else:
		cnt = max(c, cnt)
		c = 1
cnt = max(cnt, c)
print(min(cnt, n))


s = input()
i = 1
n = len(s)
ans = 0
curr = 1
while i < n:
	if s[i] != s[i - 1]:
		curr += 1
	else:
		ans = max(ans, curr)
		curr = 1
	i += 1
ans = max(ans, curr)
i = 1
new = 0
while i < n and s[i] != s[i - 1]:
	i += 1
j = n - 2
l = 1
if s[0] != s[-1]:
	while j >= i and s[j] != s[j + 1]:
		j -= 1
		l += 1
if ans != n and s[0] != s[-1]:
	ans = max(ans, l + i)
print(ans)


a = list(input())
b = []
k = 1
for i in range(len(a) - 1):
	if a[i] != a[i + 1]:
		k += 1
	else:
		b.append(k)
		k = 1
if len(b) > 0:
	if a[-1] != a[0]:
		k += b[0]
		b.append(k)
	else:
		b.append(k)
else:
	b.append(k)
print(max(b))


import sys
s = input()
n = len(s)
if n == 1:
	print(1)
	sys.exit(0)
for i in range(n - 1):
	if s[i] == s[i + 1] and s[n - 1] != s[0]:
		x = s[:i + 1]
		y = s[i + 1:n]
		s = x[::-1] + y[::-1]
ans = 1
mx = 1
for i in range(1, n):
	if s[i] != s[i - 1]:
		mx += 1
	else:
		ans = max(mx, ans)
		mx = 1
print(max(mx, ans))


s = input()
s = s + s + s
m = cur = 1
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		cur += 1
		m = max(m, cur)
	else:
		cur = 1
print(min(m, len(s) // 3))


s = input()
n = len(s)
prepos = 0
b = ''
for i in range(1, n):
	if s[i] != s[i - 1]:
		prepos = i
	else:
		break
b = s[:prepos + 1][::-1] + s[prepos + 1:][::-1]
cnt = 1
ans1 = 1
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		cnt += 1
	else:
		ans1 = max(ans1, cnt)
		cnt = 1
ans1 = max(ans1, cnt)
cnt = 1
ans2 = 1
for i in range(1, len(b)):
	if b[i] != b[i - 1]:
		cnt += 1
	else:
		ans2 = max(ans2, cnt)
		cnt = 1
ans2 = max(ans2, cnt)
print(max(ans1, ans2))


s = input().strip()
s = s + s
n = len(s)
an = 1
m = 1
for i in range(1, n):
	if s[i] != s[i - 1]:
		m += 1
		an = max(an, m)
	else:
		an = max(an, m)
		m = 1
print(min(an, n // 2))


def solve(S):
	N = len(S)
	lens = []
	start = 0
	for i in range(1, N):
		if S[i] == S[i - 1]:
			lens.append(i - start)
			start = i
	lens.append(N - start)
	best = max(lens)
	if S[0] != S[-1] and len(lens) > 1:
		best = max(best, lens[0] + lens[-1])
	return best

def main():
	S = input()
	print(solve(S))
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		s = 2 * rs() + '333'
		le = (len(s) - 3) // 2
		a = []
		for i in s:
			if i == 'b':
				a.append(0)
			if i == 'w':
				a.append(1)
			if i == '3':
				a.append(3)
		pehla = [0, 1] * len(s)
		doosra = [1, 0] * len(s)
		k = [0] * len(s)
		for i in range(len(s)):
			if a[i] == pehla[i]:
				k[i] = 1
		ans = 0
		t = 0
		for i in k:
			if i == 1:
				t += 1
			else:
				ans = max(t, ans)
				t = 0
		k = [0] * len(s)
		for i in range(len(s)):
			if a[i] == doosra[i]:
				k[i] = 1
		t = 0
		for i in k:
			if i == 1:
				t += 1
			else:
				ans = max(t, ans)
				t = 0
		print(min(le, ans))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def zebra(s, l):
	if l == 1:
		return l
	t = 1
	a = []
	for i in range(1, l):
		if s[i] == s[i - 1]:
			a.append(t)
			t = 1
		else:
			t += 1
	a.append(t)
	t = max(a)
	if s[0] == s[l - 1] or len(a) == 1:
		return t
	else:
		return max(t, a[0] + a[len(a) - 1])
s = input()
print(zebra(s, len(s)))


from itertools import cycle
s1 = input()
s = cycle(s1)
mx = 1
numb = 1
(steps, krug) = (0, 0)
cur = []
for i in s:
	if len(cur) < 2:
		cur.append(i)
	if len(cur) == 2:
		if cur[0] != cur[1]:
			numb += 1
			del cur[0]
		else:
			if numb > mx:
				mx = numb
			numb = 1
			del cur[0]
	steps += 1
	if steps == len(s1):
		krug += 1
		steps = 0
		if krug == 2:
			break
if numb // 2 == len(s1):
	mx = numb // 2
print(mx)


s = input()
a = [0] * len(s)
prev = None
l = 1
first = 0
for i in range(len(s)):
	if prev is not None and prev == s[i]:
		if first == 0:
			first = l - 1
		l = 1
	a[i] = l
	prev = s[i]
	l += 1
ans = max(a)
if s[-1] != s[0]:
	if a[-1] + first <= len(s):
		ans = max(ans, a[-1] + first)
print(ans)


def check(st):
	count = 1
	i = 1
	pre = st[0]
	maxi = 0
	pre_indx = 0
	indx = [0 for i in range(n)]
	while i < n:
		if pre != st[i]:
			count += 1
		else:
			indx[pre_indx] = count
			count = 1
			pre_indx = i
		pre = st[i]
		i += 1
	indx[pre_indx] = count
	return indx
st = input()
n = len(st)
actual_indx = check(st)
reverse_indx = check(st[::-1])
if st[0] == st[-1]:
	print(max(actual_indx))
else:
	print(min(n, max(max(actual_indx[1:]), actual_indx[0] + reverse_indx[0])))


z = list(input())
x = []
k = 1
for i in range(len(z) - 1):
	if z[i] != z[i + 1]:
		k += 1
	else:
		x.append(k)
		k = 1
if len(x) > 0:
	if z[-1] != z[0]:
		k += x[0]
		x.append(k)
	else:
		x.append(k)
else:
	x.append(k)
print(max(x))


s = input()
s += s
n = len(s)
ans = 0
temp = 1
for i in range(1, n):
	if s[i] == 'b':
		if s[i - 1] == 'w':
			temp += 1
		else:
			ans = max(ans, temp)
			temp = 1
	elif s[i - 1] == 'b':
		temp += 1
	else:
		ans = max(ans, temp)
		temp = 1
print(min(n >> 1, max(temp, ans)))


s = input()
x = len(s)
left = 1
for i in range(1, x):
	if s[i] != s[i - 1]:
		left += 1
	else:
		break
right = 1
for i in range(x - 2, -1, -1):
	if s[i] != s[i + 1]:
		right += 1
	else:
		break
count = 1
ANS = 0
for i in range(1, x):
	if s[i] != s[i - 1]:
		count += 1
	else:
		if count > ANS:
			ANS = count
		count = 1
if count > ANS:
	ANS = count
if left + right > ANS and s[0] != s[-1]:
	ANS = left + right
print(min(x, ANS))


a = input()
n = len(a)
b = []
c = 0
d = 0
for i in range(1, n):
	if a[i] == a[i - 1]:
		b.append(['bw'.find(a[c]), i - c])
		d = max(d, i - c)
		c = i
b.append(['bw'.find(a[c]), n - c])
d = max(d, n - c)
if d < n and b[0][0] == (b[-1][0] + b[-1][1]) % 2:
	d = max(d, b[-1][1] + b[0][1])
print(d)


import sys
f = sys.stdin
s = f.readline().rstrip('\r\n')
arr = []
cnt = 1
ma = 0
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		cnt += 1
	else:
		ma = max(ma, cnt)
		cnt = 1
ma = max(ma, cnt)
if ma == len(s):
	print(str(ma) + '\n')
else:
	cnt1 = 1
	cnt2 = 1
	if s[0] != s[-1]:
		for i in range(1, len(s)):
			if s[i] != s[i - 1]:
				cnt1 += 1
			else:
				break
		for i in range(len(s) - 1, 0, -1):
			if s[i] != s[i - 1]:
				cnt2 += 1
			else:
				break
		ma = max(ma, cnt1 + cnt2)
	sys.stdout.write(str(ma) + '\n')


a = list(input())
m = 1
c = 1
z = 0
for i in range(len(a) - 1):
	if a[i] != a[i + 1]:
		c += 1
	else:
		c = 1
	m = max(m, c)
if a[0] != a[-1]:
	d = 1
	f = 1
	for i in range(len(a) - 1):
		if a[i] != a[i + 1]:
			d += 1
		else:
			break
	for i in range(len(a) - 2, -1, -1):
		if a[i] != a[i + 1]:
			f += 1
		else:
			break
	z = min(len(a), d + f)
print(max(m, z))


s = input().strip()
n = len(s)
s = s + s
cnt = ans = 1
for i in range(1, len(s)):
	cnt = cnt + 1 if s[i] != s[i - 1] else 1
	ans = max(ans, cnt)
if ans > n:
	ans = n
print(ans)


s = list(input())
ans = 0
far = 0
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		far += 1
		continue
	if s[0] != s[-1]:
		s[:i + 1] = s[:i + 1][::-1]
		s[i + 1:] = s[i + 1:][::-1]
		far += 1
	else:
		ans = max(ans, far + 1)
		far = 0
print(max(far + 1, ans))


import sys

def input():
	return sys.stdin.readline().strip()
s = input()
n = len(s)
if n == 1:
	print(1)
	return
seq = [1]
for i in range(1, n):
	seq.append(seq[i - 1] + 1 if s[i] != s[i - 1] else 1)
ans = max(seq)
if ans == n:
	print(n)
	return
if s[0] != s[-1]:
	i = 1
	while i < n and s[i] != s[i - 1]:
		i += 1
	j = 1
	while j < n and s[n - 1 - j] != s[n - j]:
		j += 1
	ans = max(ans, i + j)
print(ans)


str = input('')
str = 2 * str
len = len(str)
pre = str[0]
maxlen = 1
nowlen = 1
for i in range(1, len):
	if pre == str[i]:
		maxlen = max(nowlen, maxlen)
		nowlen = 1
	else:
		nowlen += 1
	pre = str[i]
maxlen = max(maxlen, nowlen)
print('%d' % (maxlen if maxlen <= len // 2 else len // 2))


s = input()
s = s * 3
n = len(s)
(m, curr) = (1, 1)
for i in range(n - 1):
	if s[i] != s[i + 1]:
		curr += 1
		m = max(curr, m)
	else:
		curr = 1
print(min(m, n // 3))


N = list(input())
length = len(N)
N = N + N + ['x']
total = 1
dummy = []
for i in range(1, len(N)):
	if N[i] != N[i - 1] and N[i] != 'x':
		total += 1
	else:
		dummy.append(total)
		total = 1
for i in range(len(dummy)):
	if dummy[i] > length:
		dummy[i] = length
print(max(dummy))


s = input()
ans = 0
n = len(s)
i = 0
while i < len(s):
	j = i + 1
	while j != i and s[(j - 1 + n) % n] != s[j % n]:
		j = (j + 1) % n
	if j == i:
		ans = n
		break
	elif j > i:
		ans = max(j - i, ans)
	else:
		ans = max(ans, n - i + j)
		break
	i = j
print(ans)


def main():
	s = input()
	a = s[0]
	x = r = 0
	for b in s:
		if a != b:
			x += 1
			a = b
		else:
			if r < x:
				r = x
			x = 1
	if x < len(s):
		for b in s:
			if a != b:
				x += 1
				a = b
			else:
				if r < x:
					r = x
				break
	else:
		r = x
	print(r)
main()


def test_3():
	import math
	from collections import Counter
	ss = input()
	n = len(ss)
	ss = ss + ss
	max = 0
	count = 1
	for i in range(1, len(ss)):
		if ss[i] != ss[i - 1]:
			count += 1
		else:
			count = 1
		if max < count:
			max = count
	max = min(max, n)
	print(max)
test_3()


s = input()
n = len(s)
dp = [1] * n
cur = s[-1]
end = n - 1
for i in range(n - 1):
	if s[i] == cur:
		end = i
		break
	cur = s[i]
dp[n - 1] = end + 1
res = dp[n - 1]
for i in range(n - 2, -1, -1):
	if s[i] != s[i + 1]:
		dp[i] = min(n, 1 + dp[i + 1])
		res = max(dp[i], res)
print(res)


s = input()
ans = 0
(i, j) = (0, 1)
while i < len(s):
	while j < len(s) and s[j] != s[j - 1]:
		j += 1
	ans = max(j - i, ans)
	(i, j) = (j, j + 1)
if s[0] != s[-1]:
	j = 0
	while j < len(s) and s[j] != s[j - 1]:
		j += 1
	if j < len(s):
		i = len(s) - 2
		while i >= 0 and s[i] != s[i + 1]:
			i -= 1
		ans = max(ans, len(s) - 1 - i + j)
print(ans)


a = list(input())
ans = 1
l = len(a)
i = 0
while i < l:
	count = 1
	j = i + 1
	while j < l:
		if a[j] != a[j - 1]:
			count += 1
			j += 1
		else:
			break
	if i == 0:
		count1 = count
	if j == l:
		count2 = count
	ans = max(ans, count)
	i = j
if a[0] == a[-1]:
	print(ans)
else:
	print(min(l, max(ans, count1 + count2)))


s = input() * 2
ans = cur = 1
for i in range(1, len(s)):
	if s[i] != s[i - 1]:
		cur += 1
		ans = max(ans, cur)
	else:
		cur = 1
ans = min(ans, len(s) // 2)
print(ans)


import math
s = input()
n = len(s)
str = s + s
i = 0
j = 0
m = 0
while i < n:
	j = i
	while j - i + 1 < n:
		if str[j] != str[j + 1]:
			j += 1
		else:
			break
	m = max(m, j - i + 1)
	i = j + 1
print(m)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
s = list(input())
n = len(s)
l = [1]
for i in range(n - 1):
	if s[i] != s[i + 1]:
		l[-1] += 1
	else:
		l.append(1)
ans = max(l)
if len(l) > 1:
	if s[0] != s[-1]:
		ans = max(ans, l[0] + l[-1])
print(ans)


def max_zebra(str):
	res = 1
	cur = 1
	for i in range(1, len(str)):
		if str[i] != str[i - 1]:
			cur += 1
		else:
			if res < cur:
				res = cur
			cur = 1
	if res < cur:
		res = cur
	return res
str = input()
res = max_zebra(str + str)
if res > len(str):
	print(len(str))
else:
	print(res)


s = input()
c = s[0]
cnt = 1
ma = 1
for i in range(1, len(s)):
	if s[i] != c:
		cnt += 1
		c = s[i]
	else:
		ma = max(ma, cnt)
		cnt = 1
		c = s[i]
ma = max(ma, cnt)
if s[0] == s[-1] or len(s) <= 2:
	print(ma)
else:
	cnt = 1
	c = s[0]
	for i in range(1, len(s)):
		if s[i] != c:
			cnt += 1
			c = s[i]
		else:
			break
	cnt += 1
	c = s[-1]
	for i in range(2, len(s) + 1):
		if s[-i] != c:
			cnt += 1
			c = s[-i]
		else:
			break
	cnt = min(len(s), cnt)
	print(max(cnt, ma))


def matches(a, b):
	return a != b
txt = str(input())
n = len(txt)
txt = txt + txt
res = 0
j = 0
for i in range(n):
	j = max(i, j)
	while j - i + 1 < n and matches(txt[j + 1], txt[j]):
		j = j + 1
	res = max(res, j - i + 1)
print(res)


from __future__ import print_function
from collections import *
from sys import stdin
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')

def ans(s):
	ln = 0
	tmp = 1
	i = 1
	while i < len(s):
		if s[i] == s[i - 1]:
			ln = max(ln, tmp)
			tmp = 1
			i += 1
		else:
			tmp += 1
			i += 1
	return max(tmp, ln)
val = 0
s = g()
n = len(s)
val = max(val, ans(s))
if s[0] == s[-1] or val == len(s):
	print(val)
	exit()
for i in range(n):
	if s[i] == s[i + 1]:
		val = max(val, ans(s[:i + 1][::-1] + s[i + 1:][::-1]))
		break
for i in reversed(range(n)):
	if s[i] == s[i - 1]:
		val = max(val, ans(s[:i][::-1] + s[i:][::-1]))
		break
print(val)


s = input()
n = len(s)
s = s + s + s
max = cur = 1
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		cur += 1
		if max < cur:
			max = cur
	else:
		cur = 1
if max > n:
	print(n)
else:
	print(max)