var
c:char;
a:array[1..101,1..101]of longint;
i,n,j,t:longint;
b:boolean;
procedure f(x,y:longint);
begin
if (x>0)and(y>0) then begin
if a[x,y]=0 then
begin
t:=t+1;
a[x,y]:=6;
f(x-1,y);
f(x+1,y);
f(x,y+1);
f(x,y-1);
if (y=n)and(x=n) then b:=true;
end; end;
end;
begin
assign(input,'ymxpre.in');
assign(output,'ymxpre.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
for j:=1 to n do begin
read(c); a[i,j]:=ord(c)-ord('0');
if (a[i,j]=2)or(a[i,j]=5) then a[i,j]:=0; end;
f(1,1);
if b=true then writeln('yes') else writeln('no');
writeln(t);
close(input);
close(output);
end.