program gen_random;

{$APPTYPE CONSOLE}

uses SysUtils;

const
  MAXN = 20;
  MAXM = 50;

var
  i, n, j, maxDist: integer;
  m, b, e: array [1..MAXN] of integer;
  a: array[1..MAXN,1..MAXN] of integer;
  
begin
	i:=1;
	while (FileExists(IntToStr(i)+'.in')) do inc(i);
	rewrite(output,IntToStr(i)+'.in');
	
  randomize;
  
  if ParamCount > 0 then maxDist := StrToInt(ParamStr(1))
  else maxDist := 24*60;
  
  n := random(MAXN)+1;
  for i:=1 to n do m[i] := random(MAXM)+1;
  for i:=1 to n-1 do
    for j:=i+1 to n do begin
    	if i=j then a[i][j] := 0
      else a[i][j] := random(maxDist)+1;
      a[j][i] := a[i][j];
    end;
  
  for i:=1 to n do begin
  	b[i] := random(24*60-1);
  	e[i] := random(24*60-1-b[i])+b[i]+1;
  end;
  
  writeln(n);
  for i:=1 to n do begin
  	write(m[i]);
  	if (i<>n) then write(' ');
  end;
  writeln;
  
  for i:=1 to n do begin
  	writeln(Format('%.2d:%.2d %.2d:%.2d',[b[i] div 60,b[i] mod 60,e[i] div 60,e[i] mod 60]));
  end;
  
  for i:=1 to n do begin
  	for j:=1 to n do begin
  	  write(a[i][j]);
  	  if (j<>n) then write(' ');
  	end;
  	writeln;
  end;
  
  sleep(100);
end.