procedure build_next;begin lena:=length(a);lenb:=length(b); next[0]:=lenb;next[1]:=lenb-1; for i:=1 to lenb-2 do if b[i]<>b[i+1] then begin next[1]:=i;break; end; k:=1; for i:=2 to lenb-1 do begin p:=k+next[k]-1;L:=next[i-k]; if i+L<=p then next[i]:=L else begin j:=p-i+1; if j<0 then j:=0; while (i+jb[i] then begin ex[0]:=i;break; end; k:=0; for i:=1 to lena-1 do begin p:=k+ex[k]-1;L:=next[i-k]; if i+L<=p then ex[i]:=L else begin j:=p-i+1; if j<0 then j:=0; while (i+j