program
Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
OneCompt=
record
start, finish:
integer
;
n_i:
array
of
integer
;
end
;
type
comptArray=
array
of
OneCompt;
var
res:
integer
;
ccount:
Integer
;
i, dd, hh, mm:
Integer
;
s, s1:
string
;
compts:comptArray;
f:TextFile;
function
max(
const
a, b:
integer
):
integer
;
begin
if
a>b
then
result:=a
else
result:=b;
end
;
procedure
ComptSort(
var
A: comptArray; sLo, sHi:
Integer
);
var
Lo, Hi, Md:
Integer
;
T:OneCompt;
begin
Lo := sLo;
Hi := sHi;
Md := compts[(Lo + Hi)
div
2
].start;
repeat
while
A[Lo].start < Md
do
Inc(Lo);
while
A[Hi].start > Md
do
Dec(Hi);
if
Lo <= Hi
then
begin
T := compts[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo);
Dec(Hi);
end
;
until
Lo > Hi;
if
Hi > sLo
then
ComptSort(A, sLo, Hi);
if
Lo < sHi
then
ComptSort(A, Lo, sHi);
end
;
procedure
getNI(
var
A: comptArray);
var
i,j:
integer
;
begin
for
i:=
0
to
high(A)
do
begin
for
j:=i+
1
to
high(A)
do
begin
if
A[j].Start>=A[i].Finish
then
begin
setlength(A[i].n_i, length(A[i].n_i)+
1
);
A[i].n_i[high(A[i].n_i)]:=j;
end
;
end
;
end
;
end
;
Function
GetComptCount(
const
A:comptArray;
const
st:
integer
):
integer
;
var
i:
Integer
;
rc:
integer
;
begin
result:=
0
;
if
st>high(a)
then
exit;
rc:=
0
;
for
i:=
0
to
high(A[st].n_i)
do
begin
rc:=max(rc, GetComptCount(A,A[st].n_i[i]));
end
;
result:=rc +
1
;
end
;
begin
AssignFile(f,
'input.txt'
);
Reset(f);
Readln(F, ccount);
SetLength(compts,ccount);
for
i:=
0
to
ccount-
1
do
begin
Readln(F, s);
s1:=copy(s,
1
,
2
);
hh:=strtoint(s1);
s1:=copy(s,
4
,
2
);
mm:=strtoint(s1);
compts[i].start:=hh*
60
+ mm;
s1:=copy(s,
7
,
2
);
hh:=strtoint(s1);
s1:=copy(s,
10
,
2
);
mm:=strtoint(s1);
compts[i].finish:=hh*
60
+ mm;
s1:=copy(s,
13
,
2
);
dd:=strtoint(s1);
compts[i].start:=compts[i].start + dd*
24
*
60
;
compts[i].finish:=compts[i].finish + dd*
24
*
60
;
end
;
ComptSort(compts,
0
, ccount-
1
);
getNI(compts);
res:=
0
;
for
i:=
0
to
ccount-
1
do
res:=max(res, GetComptCount(compts, i));
writeln
(res);
readln;
end
.