program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,r:array[-400..601,-400..601]of longint;
  n,i,j,k:longint;
  f:text;
function find(i,j:integer):integer;
var k,s,b,r:integer;
begin
  k:=0;
  b:=0;
  r:=0;
  repeat
    inc(k);
    for s:=(-k+1) to k-1 do
      if a[i+s,j+k-abs(s)]>0 then
        begin
          r:=a[i+s,j+k-abs(s)];
          inc(b);
        end;
    for s:=(-k+1) to k-1 do
      if a[i+s,j-k+abs(s)]>0 then
        begin
          r:=a[i+s,j-k+abs(s)];
          inc(b);
        end;
    if a[i+k,j]>0 then begin inc(b);r:=a[i+k,j];end;
    if a[i-k,j]>0 then begin inc(b);r:=a[i-k,j];end;
  until(k=400)or (b>0);

  if b<>1 then r:=0;
  find:=r;
end;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  assignfile(f,'input.txt');
  reset(f);
  read(f,n);
  for i:=1 to n do
    for j:=1 to n do
      read(f,a[i,j]);
  closefile(f);
  for i:=1 to n do
    for j:=1 to n do
      if a[i,j]>0 then
        r[i,j]:=a[i,j]
      else
        r[i,j]:=find(i,j);
  assignfile(f,'output.txt');
  rewrite(f);
  for i:=1 to n do
    begin
      for j:=1 to n do
        write(f,r[i,j],' ');
      writeln(f);
    end;
  closefile(f);  
end.
