{"MIHAI VITEAZUL NATIONAL COLLEGE" ROMANIA
9084
ROXANA CARNARU
INTERMEDIATE 3}
uses crt;
var f,g,h:text;
n,k,i,j,a,b:integer;
j1,v:char;
s:string;
begin
assign(f,'inPUT.txt');
assign(g,'outPUT.txt');
assign(h,'ajt.txt');
reset(f);
rewrite(g);rewrite(h);
while not seekeof(f) do begin
read(f,s);
for k:=1 to length(s) do if s[k]=',' then s[k]:=' ';
insert(' ',s,2);
writeln(h,s);
end;
close(h);reset(h);
while not seekeof(h) do begin
read(h,j1);
read(h,i);read(h,a);readln(h,b);
if
j1='A' then j:=10;
if
j1='B' then j:=9;
if
j1='C' then j:=8;
if
j1='D' then j:=7;
if
j1='E' then j:=6;
if
j1='F' then j:=5;
if
j1='G' then j:=4;
if
j1='H' then j:=3;
if
j1='I' then j:=2;
if
j1='J' then j:=1;
n:=0;
if
a=1 then begin
if
(j+2<=10)and(i-1>0)then inc(n);
if
(j+1<=10)and(i-2>0)then inc(n);
if
(j-2>0)and(i-1>0) then inc(n);
if
(j-1>0)and(i-2>0) then inc(n);
if (j-2>0)and(i-2>0) then if b=1 then n:=n+2
else inc(n);
if (j+2<=10)and(i-2>0) then if b=1 then n:=n+2
else inc(n);
end;
if
a=2 then begin
if
(j+2<=10)and(i+1<=10)then inc(n);
if(i+2<=10)and(j+1<=10)then inc(n);
if(j-2>0)and(i+1<=10) then inc(n);
if(i+2<=10)and(j-1>0) then inc(n);
if(j-2>0)and(i+2<=10) then if b=1 then n:=n+2
else
inc(n);
if(j+2<=10)and(i+2<=10)
then if b=1 then n:=n+2
else
inc(n);
end;
writeln(g,n);
end;
close(f);
close(g);
end .