program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
const
  maxN=200;
var
  n,i,j,k,nz,d:integer;
  a:array[1..maxN,1..maxN]of integer;
  s,t,pi,pj,zi,zj:array[1..40000] of integer;

begin
  assign(input,'input.txt');
  reset(input);
  read(n);
  nz:=0;
  for i:=1 to n do for j:=1 to n do begin
     read(a[i,j]);
     if a[i,j]=0 then begin
        nz:=nz+1;
        zi[nz]:=i; zj[nz]:=j;
     end;
  end;

  Close(Input);

  for i:=1 to nz do s[i]:=maxint;

  for i:=1 to n do for j:=1 to n do if a[i,j]<>0 then
  for k:=1 to nz do begin
     d:=abs(i-zi[k])+abs(j-zj[k]);
     if d=s[k] then t[k]:=t[k]+1
     else if d<s[k] then begin
        t[k]:=1; s[k]:=d; pi[k]:=i; pj[k]:=j;
     end;
  end;

  for k:=1 to nz do
     if (t[k]=1) and (s[k]<maxint) then a[zi[k],zj[k]]:=a[pi[k],pj[k]];

  assign(output,'output.txt'); rewrite(output);
  for i:=1 to n do begin
    for j:=1 to n do write(a[i,j],' ');
    writeln;
  end;

  Close(Output);
end.
