// (C) Timofey S. Chistyakov 2005

{$apptype console}

uses
  Math, Types;

const
  MAX_ORDER = 100;

type
  TInt100Arr = array [0..MAX_ORDER] of integer;

  TSchedule = record
    Period: integer;
    Qtys: TIntegerDynArray;
    Conformed: integer;
  end;

function dayNo(Week, Day: integer): integer;
begin
  Result := (Week - 1) * 7 + (Day - 1);
end;

function periodDayNo(DayIdx, MinDay, Len: integer): integer;
var
  dayNo, minW, relDay: integer;
begin
  minW := MinDay div 7;
  dayNo := MinDay + DayIdx;
  relDay := dayNo - minW * 7;
  Result := relDay mod (Len * 7);
end;

var
  fi, fo: textfile;
  n: integer;
  orders: array of record
    Week, Day, Qty: integer;
  end;
  i, j, l: integer;
  p: array of TInt100Arr;
  minDay, maxDay: integer;
  table: TIntegerDynArray;
  dayQty: integer;
  schedule, bestSchedule: TSchedule;
begin
{  AssignFile(fi, 'input.txt');
  Reset(fi);
  AssignFile(fo, 'output.txt');
  Rewrite(fo);}

  Read(n);
  SetLength(orders, n);
  minDay := 1000;
  maxDay := -1;
  for i := 0 to n - 1 do
    with orders[i] do begin
      Read(Week, Day, Qty);
      minDay := Min(minDay, dayNo(Week, Day));
      maxDay := Max(maxDay, dayNo(Week, Day));
    end;

  SetLength(table, maxDay - minDay + 1);
  FillChar(table[0], SizeOf(table[0]) * Length(table), 0);
  for i := 0 to n - 1 do
    with orders[i] do
      table[dayNo(Week, Day) - minDay] := Qty;

  for l := 1 to 4 do begin
    SetLength(p, l * 7);
    for i := 0 to High(p) do
      FillChar(p[i], SizeOf(p[i]), 0);
    for i := 0 to High(table) do
      Inc(p[periodDayNo(i, minDay, l), table[i]]);

    schedule.Period := l;
    schedule.Conformed := 0;
    SetLength(schedule.Qtys, Length(p));

    for i := 0 to High(p) do begin
      dayQty := 0;
      for j := 1 to MAX_ORDER do
        if p[i, j] > p[i, dayQty] then
          dayQty := j;
      Inc(schedule.Conformed, p[i, dayQty]);
      schedule.Qtys[i] := dayQty;
    end;

    if schedule.Conformed > bestSchedule.Conformed then begin
      bestSchedule := schedule;
      bestSchedule.Qtys := Copy(schedule.Qtys, 0, Length(schedule.Qtys));
    end;
  end;

  Write(bestSchedule.Period);
  for i := 1 to bestSchedule.Period * 7 do
    Write(' ', bestSchedule.Qtys[i - 1]); 

//  CloseFile(fi);
//  CloseFile(fo);
end.
