Program hrt; uses crt; label lab1; type TPot=record b,e,max,now:integer; end; var sum,now:array[0..100,0..100]of integer; a:array[0..100]of TPot; { pot:array[0..10000]of Tpot; } i,j,n,b,e,m,c,mmm,kk,mm,lll:integer; begin clrscr; assign(input,'HOMEBREW.DAT'); {assign(output,'HOMEBREW.RES'); }reset(input); read(n); mm:=0; while not(EOF(input)) do begin readln(b,e,m); if e=n+1 then inc(mm); sum[b,e]:=m; end; for i:=0 to n do begin for j:=1 to n+1 do write(sum[i,j],' '); writeln; end; c:=-1; kk:=0; i:=0; lll:=-1; {for i:=0 to n+1 do} while lll<0 do begin a[i].b:=i; lab1: for j:=0 to n+1 do if (sum[i,j]>0)and(j>c) then begin c:=j; Break; end else if j=n+1 then c:=-1; a[i].e:=c; a[i].max:=sum[i,j]; if a[i].max>a[i].now then inc(a[i].now) else goto lab1; i:=j; inc(mmm); if i=n+1 then begin i:=0; inc(kk); end; if mm=kk then lll:=1; end; writeln(mmm); close(input); repeat until keypressed; end.