program Main;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
 ar_dyn=record
  y:array of integer;
 end;

type
 TPoint=record
  x:integer;
  y:integer;
 end;

var n,i,j,position:integer;
    cdt:TPoint;
    x:array of ar_dyn;

function move_left(frm:TPoint;var Num:integer):TPoint;
var cur:TPoint;
begin
 cur:=frm;
 result.x:=cur.x;
 result.y:=cur.y;
 while (cur.x>1) and (x[cur.y].y[cur.x-1]=0) do
  begin
   cur.x:=cur.x-1;
   x[cur.y].y[cur.x]:=num;
   num:=num-1;
   result.x:=cur.x;
   result.y:=cur.y;
  end
end;

function move_right(frm:TPoint;var Num:integer):TPoint;
var cur:TPoint;
begin
 cur:=frm;
 result.x:=cur.x;
 result.y:=cur.y;
 while (cur.x<n) and (x[cur.y].y[cur.x+1]=0) do
  begin
   cur.x:=cur.x+1;
   x[cur.y].y[cur.x]:=num;
   num:=num-1;
   result.x:=cur.x;
   result.y:=cur.y;
  end
end;

function move_up(frm:TPoint;var Num:integer):TPoint;
var cur:TPoint;
begin
 cur:=frm;
 result.x:=cur.x;
 result.y:=cur.y;
 while (cur.y>1) and (x[cur.y-1].y[cur.x]=0) do
  begin
   cur.y:=cur.y-1;
   x[cur.y].y[cur.x]:=num;
   num:=num-1;
   result.x:=cur.x;
   result.y:=cur.y;
  end
end;

function move_down(frm:TPoint;var Num:integer):TPoint;
var cur:TPoint;
begin
 cur:=frm;
 result.x:=cur.x;
 result.y:=cur.y;
 while (cur.y<n) and (x[cur.y+1].y[cur.x]=0) do
  begin
   cur.y:=cur.y+1;
   x[cur.y].y[cur.x]:=num;
   num:=num-1;
   result.x:=cur.x;
   result.y:=cur.y;
  end
end;

begin
  assign(input,'F.in'); reset(input);
  assign(output,'F.out'); rewrite(output);

  readln(n);

  setlength(x,n+2);

  for i:=0 to n+1 do
   setlength(x[i].y,n+2);

  for i:=1 to n do
   begin
    for j:=1 to n do
     begin
      x[i].y[j]:=0;
     end;
   end;

  position:=n*n;
  cdt.x:=n+1;
  cdt.y:=n;
  while position>=1 do
   begin
    cdt:=move_left(cdt,position);
    cdt:=move_up(cdt,position);
    cdt:=move_right(cdt,position);
    cdt:=move_down(cdt,position);
   end;

  for i:=1 to n do
   begin
    for j:=1 to n do
     begin
      write(x[i].y[j],' ');
     end;
    writeln;
   end;

  close(input);
  close(output);
end.
