program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Strutils,
  Math;

var ifile, ofile: TextFile;
    n, i, o, x, y, min, xm, ym: integer;
    a, b, c, d, e, f, g, h, l: array [1..200, 1..200] of integer;

label loh, loh2, loh3, loh4, loh5, loh6, loh7, loh8;

begin

  AssignFile(ifile, 'input.txt');
  Reset(ifile);
  Read(ifile, N);
  fillchar(a, sizeof(a), -1);
  fillchar(b, sizeof(b), -1);
  fillchar(c, sizeof(c), -1);
  fillchar(d, sizeof(d), -1);
  fillchar(e, sizeof(e), -1);
  fillchar(f, sizeof(f), -1);
  fillchar(g, sizeof(g), -1);
  fillchar(h, sizeof(h), -1);
  fillchar(l, sizeof(l), -1);
  for i := 1 to n do
   for o := 1 to n do
    read(ifile, a[i,o]);
  CLoseFile(ifile);

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         b[i,o] := 0;
         goto loh;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         b[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         b[i,o] := 0;
         goto loh;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         b[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         b[i,o] := 0;
         goto loh;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         b[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         b[i,o] := 0;
         goto loh;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         b[i,o] := a[x,y];
        end;
       end;
    loh:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         c[i,o] := 0;
         goto loh2;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         c[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         c[i,o] := 0;
         goto loh2;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         c[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         c[i,o] := 0;
         goto loh2;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         c[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         c[i,o] := 0;
         goto loh2;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         c[i,o] := a[x,y];
        end;
       end;
    loh2:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         d[i,o] := 0;
         goto loh3;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         d[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         d[i,o] := 0;
         goto loh3;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         d[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         d[i,o] := 0;
         goto loh3;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         d[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         d[i,o] := 0;
         goto loh3;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         d[i,o] := a[x,y];
        end;
       end;
    loh3:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         e[i,o] := 0;
         goto loh4;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         e[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         e[i,o] := 0;
         goto loh4;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         e[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         e[i,o] := 0;
         goto loh4;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         e[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         e[i,o] := 0;
         goto loh4;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         e[i,o] := a[x,y];
        end;
       end;
    loh4:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         f[i,o] := 0;
         goto loh5;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         f[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         f[i,o] := 0;
         goto loh5;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         f[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         f[i,o] := 0;
         goto loh5;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         f[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         f[i,o] := 0;
         goto loh5;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         f[i,o] := a[x,y];
        end;
       end;
    loh5:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         g[i,o] := 0;
         goto loh6;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         g[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         g[i,o] := 0;
         goto loh6;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         g[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         g[i,o] := 0;
         goto loh6;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         g[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         g[i,o] := 0;
         goto loh6;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         g[i,o] := a[x,y];
        end;
       end;
    loh6:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         h[i,o] := 0;
         goto loh7;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         h[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         h[i,o] := 0;
         goto loh7;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         h[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         h[i,o] := 0;
         goto loh7;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         h[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         h[i,o] := 0;
         goto loh7;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         h[i,o] := a[x,y];
        end;
       end;
    loh7:
   end;
  end;

  for i := 1 to n do begin
   for o := 1 to n do begin
    min := 1000000;
    if (i < n) and (o < n) then
     for x := i to n do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         l[i,o] := 0;
         goto loh8;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         h[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o < n) then
     for x := i downto 1 do
      for y := o to n do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         l[i,o] := 0;
         goto loh8;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         l[i,o] := a[x,y];
        end;
       end;
    if (i >= 1) and (o >= 1) then
     for x := i downto 1 do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         l[i,o] := 0;
         goto loh8;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         l[i,o] := a[x,y];
        end;
       end;
    if (i < n) and (o >= 1) then
     for x := i to n do
      for y := o downto 1 do
       if a[x,y] > 0 then begin
        if (abs(x-i) + abs(y-o) = min) and ((xm <> x) or (ym <> y)) then begin
         l[i,o] := 0;
         goto loh8;
        end;
        if abs(x-i) + abs(y-o) < min then begin
         min := abs(x-i) + abs(y-o);
         xm := x; ym := y;
         l[i,o] := a[x,y];
        end;
       end;
    loh8:
   end;
  end;

  for i := 1 to n do
   for o := 1 to n do
    if (b[i,o] <> c[i,o]) or (b[i,o] <> h[i,o]) or (b[i,o] <> l[i,o]) or (b[i,o] <> f[i,o]) or (b[i,o] <> g[i,o]) or (b[i,o] <> d[i,o]) or (b[i,o] <> e[i,o]) then
     b[i,o] := a[i,o];

  for i := 1 to n do
   for o := 1 to n do
    if b[i,o] = 0 then
     b[i,o] := a[i,o];

  AssignFile(ofile, 'output.txt');
  Rewrite(ofile);

  for i := 1 to n do
   for o := 1 to n do
    if b[i,o] = -1 then b[i,o] := 0;

  if n = 1 then begin
   write(ofile, a[1,1]);
  end else begin
   for i := 1 to n do begin
    for o := 1 to n-1 do Write(ofile, b[i,o], ' ');
    if i < n then writeln(ofile, b[i,n]);
   end;
   write(ofile, b[n,n]);
  end;
  
  CLoseFile(ofile);

end.
