https://www.luogu.org/problemnew/show/P1203
USACO是真的难。。。。。
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q,ans;
string a;
int f(int x)
{
int s=0;
char a1=a[x];
char b2=a[x+1];
for(int i=x;;i--)//往前看和往后看
{
if(a[i]==a1)s++;
else if(a[i]=='w')
s++;
else
break;
}
for(int i=x+1;;i++)
{
if(a[i]==b2)s++;
else if(a[i]=='w')
s++;
else
break;
}
return s;
}
char str;
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
ans=-1;
cin>>n;cin>>a;
a=a+a+a;
for(int i=n;i<2*n;i++)//三段 从中间那一段开始处理
{
if(a[i]==a[i+1])
continue;
if(a[i]=='w')//这TMD硬是看的到第三个点 要不然真不会
{
a[i]='r';
ans=max(ans,f(i));
a[i]='b';
ans=max(ans,f(i));
a[i]='w';
}
ans=max(ans,f(i));
}
ans=min(ans,n);//最长也不能比总长长
if(ans==-1)ans=n;//出现这种情况必定是一路continue过来的
cout<<ans<<endl;
//cout << "Hello world!" << endl;
return 0;
}