Program Poj1961;
const
maxn=10000000;
var
i,j,tt,n,duan_luo:longint;
next:array[1..maxn] of longint;
a:ansistring;
begin
tt:=1;
while (true) do
begin
readln(n);
if n=0 then break;
readln(a); inc(n); a:=a+'.';
i:=1;j:=0;next[1]:=0;
while (i<=n-1) do
begin
if (j=0) or (a[i]=a[j]) then
begin
inc(i);inc(j);
// if (a[i]<>a[j]) then next[i]:=j else next[i]:=next[j];
next[i]:=j;
end
else j:=next[j];
end;
writeln('Test case #',tt);
for i:=2 to n do
begin
duan_luo:=i-next[i];
if (duan_luo>0) and ((i-1) mod duan_luo=0) and ((i-1) div duan_luo>1) then
writeln(i-1,' ',(i-1) div duan_luo);
end;
// readln;
writeln;
inc(tt);
end;
end.
Program BlueJeans;
const
maxn=60;
maxm=10;
var
tt,i,j,k,n,m:longint;
a:array[1..maxm] of string;
next:array[1..maxn] of longint;
p,ans:string;
flag:boolean;
function kmp(a,s:string):boolean;
var
i,j,n:longint;
begin
n:=length(a);
j:=0; next[1]:=0; i:=1;
while i<n do
begin
if (j=0) or (a[i]=a[j]) then
begin
inc(i); inc(j);
if (a[i]<>a[j]) then next[i]:=j else next[i]:=next[j];
end else j:=next[j];
end;
j:=0; i:=0;
while (i<=maxn) and (j<=n) do
begin
if (j=0) or (a[j]=s[i]) then
begin
inc(i); inc(j);
// if (j=n) then exit(true);
end else j:=next[j];
end;
if j>n then exit(true);
exit(false);
end;
function compare(a,b:string):boolean;
var
i,n,m:longint;
begin
n:=length(a); m:=length(b);
if (n<>m) then exit(n<m);
for i:=1 to n do if (a[i]<>b[i]) then exit(ord(a[i])>ord(b[i]));
exit(false);
end;
begin
readln(tt);
while (tt>0) do
begin
ans:='';
readln(m);
for i:=1 to m do readln(a[i]);
for i:=1 to maxn do
for j:=i to maxn do
begin
p:=copy(a[1],i,j-i+1);
flag:=false;
for k:=2 to m do
begin
if not(kmp(p,a[k])) then begin flag:=true; break; end;
end;
if not(flag) and (compare(ans,p)) then ans:=p;
end;
if length(ans)<3 then writeln('no significant commonalities')
else writeln(ans);
dec(tt);
end;
end.
Program SeekName;
const
maxn=400000;
var
n,i,j,size:longint;
a:ansistring;
ans,next:array[1..maxn] of longint;
begin
while not seekeof do
begin
readln(a); a:=a+'.';
n:=length(a);
j:=0;next[1]:=0;i:=1;
while (i<n) do
begin
if (j=0) or (a[i]=a[j]) then
begin
inc(i);
inc(j);
// if (a[i]<>a[j]) then next[i]:=j else next[i]:=next[j];
next[i]:=j;
end else j:=next[j];
end;
size:=0; j:=n;
repeat
inc(size);
ans[size]:=j-1;
j:=next[j];
until j<=1;
write(ans[size]);
for i:=size-1 downto 1 do write(' ',ans[i]);
writeln;
end;
end.
Program poj3468;
const
maxn=100000;
maxq=100000;
var
n,m,i,j,k:longint;
lazy,t:array[1..maxn*8] of int64;
c:char;
Procedure pushup(root:longint);
begin
t[root]:=t[root*2]+t[root*2+1];
end;
Procedure build(l,r,root:longint);
var
m:longint;
begin
if (l=r) then
begin
read(t[root]);
exit;
end;
m:=(l+r) shr 1;
build(l,m,root*2);
build(m+1,r,root*2+1);
pushup(root);
end;
Procedure Pushdown(l,r,root:longint);
var
m:longint;
begin
m:=(l+r) shr 1;
if (lazy[root]=0) then exit;
inc(lazy[root shl 1],lazy[root]);
inc(lazy[root shl 1+1],lazy[root]);
inc(t[root shl 1],lazy[root]*(m-l+1));
inc(t[root shl 1+1],lazy[root]*(r-(m+1)+1));
lazy[root]:=0;
end;
Procedure update(l,r,nowl,nowr,root,cost:longint);
var
m:longint;
begin
if (l<=nowl) and (nowr<=r) then
begin
inc(lazy[root],cost);
inc(t[root],(nowr-nowl+1)*cost);
exit;
end;
pushdown(nowl,nowr,root);
m:=(nowl+nowr) shr 1;
if (l<=m) then update(l,r,nowl,m,root*2,cost);
if (m+1<=r) then update(l,r,m+1,nowr,root*2+1,cost);
pushup(root);
end;
function query(l,r,nowl,nowr,root:longint):int64;
var
m:longint;
res:int64;
begin
if (l<=nowl) and (nowr<=r) then
begin
exit(t[root]);
end;
pushdown(nowl,nowr,root);
m:=(nowl+nowr) shr 1;
res:=0;
if (l<=m) then res:=res+query(l,r,nowl,m,root*2);
if (m+1<=r) then res:=res+query(l,r,m+1,nowr,root*2+1);
exit(res);
end;
begin
readln(n,m);
fillchar(lazy,sizeof(lazy),0);
build(1,n,1);
readln;
while (m>0) do
begin
read(c);
if c='Q' then
begin
readln(i,j);
writeln(query(i,j,1,n,1));
end
else
begin
readln(i,j,k);
update(i,j,1,n,1,k);
end;
dec(m);
end;
end.