program aaa;

{$APPTYPE CONSOLE}

var
  a:array[1..200, 1..200] of integer;
  n:integer;

  z:array[0..40000] of record
      x,y:integer;
      value:integer;
      count:integer;
      dist:integer;
    end;
  zn:integer=0;

  nz:array[0..40000] of record
      x,y:integer;
    end;
  nzn:integer=0;

  i,j:integer;

  tdist:integer;

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

begin
  { TODO -oUser -cConsole Main : Insert code here }

  //input
  assignfile(input, 'input.txt');
  reset(input);
  readln(n);
  for i:=1 to n do
    for j:=1 to n do
      begin
        read(a[j,i]);
        if a[j,i]=0 then
          begin
            with z[zn] do
              begin
                x:=j;
                y:=i;
              end;
            inc(zn);
          end
        else
          begin
            with nz[nzn] do
              begin
                x:=j;
                y:=i;
              end;
            inc(nzn);
          end;

      end;
  close(input);

  for i:=0 to nzn-1 do
    begin
      for j:=0 to zn-1 do
        begin
          tdist:=distance(nz[i].x, nz[i].y,
            z[j].x, z[j].y);
          if  (tdist < z[j].dist) or (z[j].count=0) then
            begin
              z[j].dist:=tdist;
              z[j].count:=1;
              z[j].value:=a[nz[i].x,nz[i].y];
            end
          else if tdist=z[j].dist then
            inc(z[j].count);
        end;
    end;

  for i:=0 to zn-1 do
    with z[i] do
      if count=1 then
        a[x,y]:=value;



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

end.
