/* ID: chinux1 PROG: beads LANG: C++11 */#include <iostream>#include <fstream>#include <string>#include <vector>#include <map>usingnamespacestd;intcountBeadsBackward(stringnecklace,intindex){if(index>0){charfirstColor=necklace[index-1];inti=index-1;while(i>0&&(firstColor==necklace[i]||necklace[i]=='w'||firstColor=='w')){// first Color may be 'w', if so, we need to updateif(firstColor=='w'&&necklace[i]!='w'){firstColor=necklace[i];}i--;}returnindex-1-i;}else{return0;}}intcountBeadsForward(stringnecklace,intindex){if(index<necklace.size()){charfirstColor=necklace[index];inti=index;while(i<necklace.size()&&(firstColor==necklace[i]||necklace[i]=='w'||firstColor=='w')){// first Color may be 'w', if so, we need to updateif(firstColor=='w'&&necklace[i]!='w'){firstColor=necklace[i];}i++;}returni-index;}else{return0;}}intcountBeads(stringnecklace,intindex){returncountBeadsBackward(necklace,index)+countBeadsForward(necklace,index);}intmaxNumberOfBeads(stringdoubleNecklace){intmaxBeads=0;for(inti=1;i<doubleNecklace.length();i++){intnum=countBeads(doubleNecklace,i);if(num>maxBeads){maxBeads=num;}}returnmaxBeads;}intmain(){ofstreamfout("beads.out");ifstreamfin("beads.in");// Line 1intN=0;fin>>N;// Line 2stringnecklace;fin>>necklace;stringdoubleNecklace=necklace+necklace;fout<<min(maxNumberOfBeads(doubleNecklace),N)<<endl;return0;}