7 sa
,tsa
,rk
,trk
,sum
,h
:array [0..maxn
] of longint;
9 procedure suffix_array(var s
:ansistring
);
14 fillchar(sum
,sizeof(sum
),0);
20 for i
:=1 to 255 do inc(sum
[i
],sum
[i
-1]);
30 if trk
[sa
[i
]]<>trk
[sa
[i
-1]] then inc(p
);
36 move(rk
,trk
,sizeof(rk
));
37 fillchar(sum
,sizeof(sum
),0);
55 for i
:=1 to n
do inc(sum
[i
],sum
[i
-1]);
58 sa
[sum
[rk
[i
]]]:=tsa
[i
];
65 if (trk
[sa
[i
]]<>trk
[sa
[i
-1]]) or (trk
[sa
[i
]+j
]<>trk
[sa
[i
-1]+j
]) then inc(p
);
74 if rk
[i
]=1 then continue
;
76 while s
[i
+p
]=s
[j
+p
] do inc(p
);
82 function kmp(var p
,t
:ansistring
):longint;
85 next
:array [0..maxn
] of longint;
93 while (j
>0) and (p
[j
+1]<>p
[i
]) do j
:=next
[j
];
94 if p
[j
+1]=p
[i
] then inc(j
);
101 while (j
>0) and (p
[j
+1]<>t
[i
]) do j
:=next
[j
];
102 if p
[j
+1]=t
[i
] then inc(j
);
120 for i
:=2 to n
do if h
[i
]>h
[k
] then k
:=i
;
121 st
:=copy(s
,sa
[k
],h
[k
]);
122 if st
='' then writeln('No repetitions found!') else
123 writeln(st
,' ',kmp(st
,s
));