program f;

{$APPTYPE CONSOLE}

uses math;
var inf,outf:text;

 qq:array[-250..450,-250..450] of integer;
 oo:array[1..204,1..204] of integer;

 count:int64;    n,i,k,j:integer;
 a:boolean;
 prmin,min1:integer;
 mx,my,x,y:integer;
 //prmx,prmy:integer;

 function rasst(x1,y1,x2,y2:integer):integer;
 begin
  rasst:=abs(x1-x2)+abs(y1-y2);
 end;

begin

assign(inf,'Input.txt');
assign(outf,'Output.txt');
reset(inf);
rewrite(outf);
read(inf,n);
for i:=1 to n do
for j:=1 to n do begin
read(inf,qq[i,j]); oo[i,j]:=qq[i,j]   end;

 for i:=1 to n do
 for j:=1 to n do
 if qq[i,j]=0 then
 begin min1:=11110;prmin:=-22222;
    mx:=i;my:=j;
  for k:=1 to max(max(i,n-i),max(j,n-j)) do
  begin
     if rasst(i,j,mx,my)>k*2{+1} then break;
   
   if i-k>0 then
   begin x:=i-k;
   for y:=max(j+k-rasst(i,j,mx,my)-1,1) to min(j-k+rasst(i,j,mx,my)+1,n{+1}) do
    if (qq[x,y]<>0)and(rasst(i,j,x,y)<=min1) then
    begin
    
    prmin:=min1;//prmx:=mx;prmy:=my;
    min1:=rasst(i,j,x,y);
    mx:=x;my:=y;
    end;
   end;
   
   if i+k<n+1 then
   begin   x:=i+k;
   for y:=max(1,j+k-rasst(i,j,mx,my)-1) to min(n,j-k+rasst(i,j,mx,my)+1) do
    if (qq[x,y]<>0)and(rasst(i,j,x,y)<=min1) then
    begin
        prmin:=min1;//prmx:=mx;prmy:=my;
    min1:=rasst(i,j,x,y);
    mx:=x;my:=y;
    end;
   end;
   
   if j-k>0 then
   begin y:=j-k;
   for x:=max(1,i+k-rasst(i,j,mx,my)) to min(n,i-k+rasst(i,j,mx,my)) do
    if (qq[x,y]<>0)and(rasst(i,j,x,y)<=min1) then
    begin
        prmin:=min1;//prmx:=mx;prmy:=my;
    min1:=rasst(i,j,x,y);
    mx:=x;my:=y;
    end;
   end;
  
   if j+k<n+1 then
   begin  y:=j+k;
   for x:=max(1,i+k-rasst(i,j,mx,my)) to min(n,i-k+rasst(i,j,mx,my)) do
    if (qq[x,y]<>0)and(rasst(i,j,x,y)<=min1) then
    begin
        prmin:=min1;//prmx:=mx;prmy:=my;
    min1:=rasst(i,j,x,y);
    mx:=x;my:=y;
    end;
   end;
//if ((minx=x-k)and(miny=y-k))or((minx=x-k)and(miny=y+k))or((minx=x+k)and(miny=y-k))or((minx=x+k)and(miny=y+k)) then continue;


  end;
if (min1<>11110)and(prmin>min1) then begin oo[i,j]:=qq[mx,my]; {break}end;
//if (min<>11110)and(prmin<>11110) then begin break end;
 end;

for i:=1 to n do
begin
for j:=1 to n do
write(outf,oo[i,j],' ');
if i<>n then writeln(outf);
end;
close(inf);
close(outf);
end.
