{$apptype console}

uses 
  SysUtils;

{$I gens.inc}

var
  i, j: integer;
  z, p: integer;
begin
  RandSeed := StrToInt(ParamStr(1));
  z := StrToInt(ParamStr(2));
  p :=  StrToInt(ParamStr(3));

  writeln(MAXD, ' ', MAXN);
  for i := 1 to MAXN do begin
    write(Random(10000) + 1);
    if Random(p) = 0 then
      for j := 1 to MAXD do
        write(' ', 2)
    else
      for j := 1 to MAXD do
        if random(z) = 0 then
          write(' ', 1)
        else
          write(' ', 2);
    if Random(p) = 0 then
      for j := 1 to MAXD do
        write(' ', 1)
    else
      for j := 1 to MAXD do
        write(' ', Random(2));
    writeln;
  end;
end.