# include <stdio.h>
int N;
char s[701];
int beads(int lx,int rx)
{
int i;
int lr=0,lb=0,rr=0,rb=0;
int lr1=0,lb1=0,rr1=0,rb1=0;
for (i=lx;i<=rx;i++)
{
if ((s[i]!='r')&&(s[i]!='w')) lr1=1;
else
if (lr1==0)
lr++;
if ((s[i]!='b')&&(s[i]!='w')) lb1=1;
else
if (lb1==0)
lb++;
if (lr<lb) lr=lb;
}
for (i=rx;i>=lx;i--)
{
if ((s[i]!='r')&&(s[i]!='w')) rr1=1;
else
if (rr1==0)
rr++;
if ((s[i]!='b')&&(s[i]!='w')) rb1=1;
else
if (rb1==0)
rb++;
if (rr<rb) rr=rb;
}
if (lr+rr>N)
return(N);
else
return (lr+rr);
}
main ()
{
int i,max=0,t;
FILE *in=fopen("beads.in","r");
FILE *out=fopen("beads.out","w");
fscanf (in,"%d\n",&N);
for (i=1;i<=N;i++)
{
fscanf (in,"%c",&s[i]);
s[N+i]=s[i];
}
for (i=1;i<=N;i++)
{
t=beads(i,i+N-1);
if (t>max) max=t;
}
fprintf (out,"%d\n",max);
fclose(in);
fclose(out);
exit(0);
}
int N;
char s[701];
int beads(int lx,int rx)
{
int i;
int lr=0,lb=0,rr=0,rb=0;
int lr1=0,lb1=0,rr1=0,rb1=0;
for (i=lx;i<=rx;i++)
{
if ((s[i]!='r')&&(s[i]!='w')) lr1=1;
else
if (lr1==0)
lr++;
if ((s[i]!='b')&&(s[i]!='w')) lb1=1;
else
if (lb1==0)
lb++;
if (lr<lb) lr=lb;
}
for (i=rx;i>=lx;i--)
{
if ((s[i]!='r')&&(s[i]!='w')) rr1=1;
else
if (rr1==0)
rr++;
if ((s[i]!='b')&&(s[i]!='w')) rb1=1;
else
if (rb1==0)
rb++;
if (rr<rb) rr=rb;
}
if (lr+rr>N)
return(N);
else
return (lr+rr);
}
main ()
{
int i,max=0,t;
FILE *in=fopen("beads.in","r");
FILE *out=fopen("beads.out","w");
fscanf (in,"%d\n",&N);
for (i=1;i<=N;i++)
{
fscanf (in,"%c",&s[i]);
s[N+i]=s[i];
}
for (i=1;i<=N;i++)
{
t=beads(i,i+N-1);
if (t>max) max=t;
}
fprintf (out,"%d\n",max);
fclose(in);
fclose(out);
exit(0);
}