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: competition

Starter code:

Solutions:
#!/bin/python3

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


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)


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

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)


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)


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)

3

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


def __starting_point():
    main()

__starting_point()

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)
#print(ans)
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)
else:
    if s[0] == s[-1] or res1 + res2 > len(s):
        print(ans)
    else:
        print(max(ans, res1 + res2))

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


import sys

s = input()

n = len(s)

if n == 1:
	print(1)
	return
	
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()
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)

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

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
    else:
        if 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
    else:
        if 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()
c = 1
mx = 1
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        c += 1
    else:
        if s[0] != s[-1]:
            s = s[:i + 1][::-1] + s[i + 1:][::-1]
            c += 1
            # print(s)
        else:
            if c > mx:
                mx = c
            c = 1
    # print(s)
print(max(mx, c))


#!/usr/bin/env python3
from sys import stdin, stdout

def rint():
    return list(map(int, stdin.readline().split()))
#lines = stdin.readlines()

s = list(input())
n = len(s)

# i : rightmost position of left string
for i in range(0, n-1):
    #print(0,i,i+1, n)
    #print(s[0:i+1], s[i+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)




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


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)


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

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)


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
        else:
            if(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
    else:
        if(s[j]!=s[j-1]):
            tempans+=1
            fans=max(tempans,fans)
            j-=1
            counter-=1
        else:
            if(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
        else:
            if(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
    else:
        if(s[j]!=s[j+1]):
            tempans+=1
            fans=max(tempans,fans)
            j+=1
            counter+=1
        else:
            if(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)



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)
else:
	if word[0] != word[-1]:
		poss = left + right
		if poss > len(word):
			print(len(word))
		else:
			print(max(poss, maximum))
	else:
		print(maximum)


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

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


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)