当前位置: 首页 > 工具软件 > Zebra.berlios > 使用案例 >

Plasticine zebra

南宫正阳
2023-12-01

C. Plasticine zebra

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 00 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 ss (1≤|s|≤1051≤|s|≤105, where |s||s| denotes the length of the string ss) 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 →→w|wbwwwbwb →→ wbwbwwwbw, that gives the answer equal to 55.

In the second example no operation can increase the answer.


题意:有一个字符串(只有b、w),通过断开和连接字符串,统计b、w交替出现的次数

方法:将字符串变成环,统计其中bw交替出现的次数,用sum表示前后两个元素是否相同的次数,ans为最终不同的个数

 bwwwbwwbwbwwwbwwbw
sum21123123451123123 
ans22223333455555555 
#include <bits/stdc++.h>

using namespace std;

int main(){
	string a;
	while(cin >> a){
		int len1 = a.size();
		a = a + a;
		int len =  a.size();
		int sum =1 ;
		int ans = 1;
		for(int i=0;i<len-1;i++){
			if(a[i] != a[i+1]){
				sum++;
				ans = max(ans,sum);
			}
			else
				sum =1;
		}
		ans = min(len1,ans);
		cout << ans <<endl;
	}
} 

 

 类似资料:

相关阅读

相关文章

相关问答