F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Greed is good

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 149    Accepted Submission(s): 63


Problem Description
As we all know Uncle CTW is a very greedy uncle,he likes collecting jewels.One day he gets a necklace with beautiful gems,he has a strange habit,that he only collects the contiguous gems with with same color.That means if he pick a red gem at first,and he will continue to pick only if the next gem is red,or he will stop.(That's why people call him "Uncle.Strange").
As it is a necklace,he must find somewhere to cut the necklace at the very begining,then select an end to pick until meet a different color gem,and do the same for the other end (which might not be of the same color as the gems collected before this).
There are only three kinds of gems,red('r'),pink('p'),and white('w'),and NOTICE that,because the white one could be painted,so it can be seen as either color.(See the sample for detail.)
Now he just want to know the maximum number of gems he can collect,could you tell him?
 

Input
The first line contain an integer T,then T lines,each line with a string only contain r,p or w ,with length no more than 400.
 

Output
One integer per line indicating the maximum nunber.
 

Sample Input
1 wwwpprwrprprrprprwrwwrpwrwrrp
 

Sample Output
11 Hint: Consider two copies of the beads (kind of like being able to runaround the ends). The string of 11 is marked. wwwpprwrprprrprprwrwwrpwrwrrp wwwpprwrprprrprprwrwwrpwrwrrp ****** *****
 

Author
teddy
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 19:59:59, Gzip enabled