{$apptype console}

uses
  Math, SysUtils, Types;

var
  n: integer;
  m: array of TByteDynArray;
  i, j: integer;
  corner: integer;
begin
  n := StrToInt(Paramstr(1));
  corner := StrToInt(Paramstr(2));
  
  SetLength(m, n, n);
  for i := 0 to n - 1 do
    for j := 0 to n - 1 do
       m[i, j] := 0;

  for i := 0 to n div 2 do
    case corner of
      1:
        m[(n - 1) - i, (n - 1) - i] := 255;
      2:
        m[i, (n - 1) - i] := 255;
      3:
        m[(n - 1) - i, i] := 255;
      4:
        m[i, i] := 255;
    end;

  Writeln(n);
  for i := 0 to n - 1 do begin
    for j := 0 to n - 1 do
      Write(m[i, j], ' ');
    Writeln;
  end;
end.
