{$apptype console}

// (C) Timofey S. Chistyakov 2005

uses
  Types, SysUtils;

var
  n, ns: integer;
  i, j: integer;
begin
  RandSeed := StrToInt(ParamStr(1));
  n := StrToInt(ParamStr(2));

  ns := n * n;
  Writeln(n);
  for i := 0 to ns - 1 do begin
    for j := 0 to ns - 1 do
      Write(Random(ns + 1), ' ');
    Writeln;
  end;
end.
