{BRINZA LIVIU FLAVIUS
"MIHAI VITEAZUL" NATIONAL COLLEGE
CODE 8055
ROMANIA
SENIOR 3
}
uses crt;
type mat=array[1..2,1..10]
of 0..2;
var fl:mat;
f,g,h:text; down,right,mut,last:boolean;
s:string[50];
n,i,j,st,k,l:byte;
procedure zero(var fl:mat);
begin
for k:=1 to 2 do
for l:=1 to 10 do
fl[k,l]:=0;
end;
begin
clrscr;
assign(f,'input.txt');
reset(f);
assign(g,'output.txt');
rewrite(g);
assign(h,'help.txt');
rewrite(h);
while not(seekeof(f)) do
begin
readln(f,s);
while pos(',',s)<>0 do
begin
insert(' ',s,pos(',',s));
delete(s,pos(',',s),1);
end;
writeln(h,s);
end;
close(f);
reset(h);
while not seekeof(h) do
begin
zero(fl);
read(h,n);
for i:=1 to n do
begin
read(h,j);
fl[2,j]:=1;
end;
read(h,st);
for i:=2 to st do
begin
right:=false;
last:=false;
for j:=1 to 10 do
begin
down:=false;
mut:=false;
if (fl[2,j]=0)and(fl[2,10]=1)and(j=1) then
begin
fl[2,j]:=1;
fl[2,10]:=0;
mut:=true;
last:=true;
end;
if mut=false then
begin
if ((j=10)and(last=false))or(j<>10) then
if (fl[1,j]=1)and(fl[2,j]=0) then
begin
fl[2,j]:=1;
fl[1,j]:=0;
down:=true;
mut:=true;
end;
if (down=false) and (right=false) then
if (fl[2,j]=1)and(fl[2,j+1]=0)and(j<10) then
begin
fl[2,j+1]:=1;
fl[2,j]:=0;
right:=true;
mut:=true;
end
else
if (fl[2,j]=1)and(fl[1,j]=0) then
begin
fl[1,j]:=1;
fl[2,j]:=0;
right:=false;
mut:=true;
end
else
right:=false;
end;
if mut=false then
right:=false;
end;
end;
st:=0;
for j:=1 to 10 do
if fl[2,j]=1 then
inc(st);
writeln(g,st);
end;
close(g);
close(h);
end.