CHAIN2 - Chuỗi từ
Tác giả: flashmt
Ngôn ngữ: Pascal
const fi='';
fo='';
maxn=250250;
type ar=array[1..maxn] of ansistring;
var n,re:longint;
a:ar;
f,d:array[0..maxn] of longint;
procedure rf;
var i:longint;
begin
assign(input,fi);
reset(input);
readln(n);
for i:=1 to n do readln(a[i]);
close(input);
end;
procedure sort(l,r:longint);
var i,j:longint; x,y:ansistring;
begin
i:=l; j:=r; x:=a[(i+j) div 2];
repeat
while a[i]<x do i:=i+1;
while a[j]>x do j:=j-1;
if i<=j then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
procedure pr;
var i,j,l:longint;
begin
sort(1,n);
for i:=2 to n do
begin
for j:=i-1 downto 1 do
begin
if a[i][1]<>a[j][1] then break;
if pos(a[j],a[i])=1 then
begin
d[i]:=j; break;
end;
end;
end;
f[1]:=1; re:=1;
for i:=2 to n do
begin
f[i]:=f[d[i]]+1;
if f[i]>re then re:=f[i];
end;
end;
procedure wf;
begin
assign(output,fo);
rewrite(output);
write(re);
close(output);
end;
begin
rf;
pr;
wf;
end.