{$apptype console}

uses
  Math, SysUtils;

var
  i, n: integer;
  used: array [1..365] of boolean;
  day: integer;
begin
  RandSeed := StrToInt(ParamStr(1));
  n := StrToInt(ParamStr(2));
  n := Min(n, 54);
  Writeln(n);
  for i := 1 to n do begin
    repeat
      day := Random(365) + 1;
    until not used[day];
    used[day] := true;
    writeln(
      (day - 1) div 7 + 1, ' ', (day - 1) mod 7 + 1, ' ', Random(100) + 1);
  end;
end.
