Pagini recente » Cod sursa (job #2626101) | Cod sursa (job #2918753) | Cod sursa (job #2688245) | Cod sursa (job #2534241) | Cod sursa (job #78761)
Cod sursa(job #78761)
program prefix;
const
fin='prefix.in';
fout='prefix.out';
var
t,i,j,n,k,q,l,x,y,it,best:longint;
p:array[0..1000000] of char;
pi:array[0..1000000] of longint;
begin
assign(input,fin);assign(output,fout);
reset(input);rewrite(output);
readln(t);
for it:=1 to t do
begin
l:=0;
while not(eoln(input)) do
begin
inc(l);
read(p[l]);
end;
readln;
k:=0;
pi[1]:=0;
for q:=2 to l do
begin
while (k>0) and (p[k+1]<>p[q]) do
k:=pi[k];
if p[k+1]=p[q] then
inc(k);
pi[q]:=k;
end;
best:=0;
for i:=2 to l do
begin
x:=pi[i]-pi[pi[i]];
if x<>0 then
if (i mod x=0) and (i<>x) then
if i-pi[i]=x then
if best<i then
best:=i;
end;
writeln(best);
end;
close(input);close(output);
end.