{
ID:tsnoi201
PROG:beads
LANG:PASCAL
}
program beads;
var i,n,t:longint;
a:array[0..801] of longint;
left,right:array[0..801,1..2] of longint;
c:char;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
begin
assign(input,'beads.in');
reset(input);
assign(output,'beads.out');
rewrite(output);
fillchar(left,sizeof(left),0);
fillchar(right,sizeof(right),0);
readln(n);
for i:=1 to n do
begin
read©;
if c='w' then a[i]:=0;
if c='r' then a[i]:=1;
if c='b' then a[i]:=2;
a[i+n]:=a[i];
end;
n:=n*2;
for i:=1 to n do
if a[i]=0 then
begin
left[i,1]:=left[i-1,1]+1;
left[i,2]:=left[i-1,2]+1;
end else
if a[i]=1 then
begin
left[i,1]:=left[i-1,1]+1;
left[i,2]:=0;
end else
if a[i]=2 then
begin
left[i,1]:=0;
left[i,2]:=left[i-1,2]+1;
end;
for i:=n downto 1 do
if a[i]=0 then
begin
right[i,1]:=right[i+1,1]+1;
right[i,2]:=right[i+1,2]+1;
end else
if a[i]=1 then
begin
right[i,1]:=right[i+1,1]+1;
right[i,2]:=0;
end else
if a[i]=2 then
begin
right[i,1]:=0;
right[i,2]:=right[i+1,2]+1;
end;
t:=0;
for i:=1 to n-1 do
t:=max(t,max(left[i,1],left[i,2])+max(right[i+1,1],right[i+1,2]));
if t>n div 2 then writeln(n div 2) else writeln(t);
close(output);
end.
ID:tsnoi201
PROG:beads
LANG:PASCAL
}
program beads;
var i,n,t:longint;
a:array[0..801] of longint;
left,right:array[0..801,1..2] of longint;
c:char;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
begin
assign(input,'beads.in');
reset(input);
assign(output,'beads.out');
rewrite(output);
fillchar(left,sizeof(left),0);
fillchar(right,sizeof(right),0);
readln(n);
for i:=1 to n do
begin
read©;
if c='w' then a[i]:=0;
if c='r' then a[i]:=1;
if c='b' then a[i]:=2;
a[i+n]:=a[i];
end;
n:=n*2;
for i:=1 to n do
if a[i]=0 then
begin
left[i,1]:=left[i-1,1]+1;
left[i,2]:=left[i-1,2]+1;
end else
if a[i]=1 then
begin
left[i,1]:=left[i-1,1]+1;
left[i,2]:=0;
end else
if a[i]=2 then
begin
left[i,1]:=0;
left[i,2]:=left[i-1,2]+1;
end;
for i:=n downto 1 do
if a[i]=0 then
begin
right[i,1]:=right[i+1,1]+1;
right[i,2]:=right[i+1,2]+1;
end else
if a[i]=1 then
begin
right[i,1]:=right[i+1,1]+1;
right[i,2]:=0;
end else
if a[i]=2 then
begin
right[i,1]:=0;
right[i,2]:=right[i+1,2]+1;
end;
t:=0;
for i:=1 to n-1 do
t:=max(t,max(left[i,1],left[i,2])+max(right[i+1,1],right[i+1,2]));
if t>n div 2 then writeln(n div 2) else writeln(t);
close(output);
end.