{$apptype console}

uses
  Types, Math, SysUtils;

const
  MAX_TRIES = 10;
  
type
  TSchedule = record
    Period: integer;
    Qtys: TIntegerDynArray;
  end;

var
  orders: array of record
    Week, Day, Qty: integer;
  end;


  function addOrder(AWeek, ADay, AQty: integer): boolean;
  var
    i: integer;
  begin
    for i := 0 to High(orders) do
      with orders[i] do
        if (Week = AWeek) and (Day = ADay) then begin
          Result := false;
          Exit;
        end;
    SetLength(orders, Length(orders) + 1);
    if AQty > 100 then
      AQty := 100;
    with orders[High(orders)] do begin
      Week := AWeek;
      Day := ADay;
      Qty := AQty;
    end;
    Result := true;
  end;

var
  normal: boolean;
  i, j, t: integer;
  howOften: integer;
  schedule: TSchedule;
  week, day, qty, sQty: integer;
  action: integer;
begin
  RandSeed := StrToInt(ParamStr(1));
  schedule.Period := StrToInt(ParamStr(2));
  howOften := StrToInt(ParamStr(3));

  SetLength(schedule.Qtys, schedule.Period * 7);
  for i := 0 to High(schedule.Qtys) do
    if Random(2) = 0 then
      schedule.Qtys[i] := 0
    else
      schedule.Qtys[i] := Random(99) + 2;

  for i := 1 to (50 div schedule.Period) do
    for j := 1 to 7 * schedule.Period do begin
      normal := false;
      week := ((i - 1) * 7 * schedule.Period + (j - 1)) div 7 + 1;
      day := (j - 1) mod 7 + 1;
      sQty := schedule.Qtys[j - 1];
      action := Random(howOften);
      case action of
        0:     // change qty
          addOrder(week, day, Random(100) + 1);
        1:;    // cancel
        2:     // other date
          if (sQty <> 0) then begin
            for t := 1 to MAX_TRIES do
              if addOrder(Random(week) + 1, Random(7) + 1, sQty) then
                Break;
          end;
        3:     // new order
          if (sQty <> 0) then begin
            qty := Random(100) + 1;
            for t := 1 to MAX_TRIES do
              if addOrder(Random(week) + 1, Random(7) + 1, qty) then
                Break;
            normal := true;
          end;
        else
          normal := true;
      end;
      if normal and (sQty <> 0) then
        addOrder(week, day, sQty);
    end;

  Writeln(Length(orders));
  for i := 0 to High(orders) do
    with orders[i] do
      writeln(Week, ' ', Day, ' ', Qty);
end.
