Pagini recente » Cod sursa (job #270806) | Cod sursa (job #3281171) | Rating infoarena | Cod sursa (job #3272285) | Cod sursa (job #106096)
Cod sursa(job #106096)
program abc2;
const
fin='abc2.in';
fout='abc2.out';
lmax=25;
nmax=51000;
tr:array['a'..'c'] of byte=(0,1,2);
type
vint=array[0..10000000] of byte;
vhash=array[0..30] of longint;
var
f:text;
d,dd:array[0..nmax] of int64;
a:^vint;
cuv:array[0..25] of byte;
lga,lg,i,n,nn,logmax,x,y:longint;
c,p3,pmax,aux:int64;
ch:char;
hash:array[0..10000000] of ^vhash;
num:longint;
function query(x:int64):boolean;
var
i:longint;
log:longint;
begin
log:=logmax;
i:=0;
while log>=0 do
begin
if i+1 shl log<=nn then
if x>=dd[i+(1 shl log)] then
inc(i,1 shl log);
dec(log);
end;
query:=(x=dd[i]);
end;
procedure qsort(st,dr:longint);
var
i,j:longint;
tmp,x:int64;
begin
i:=st;j:=dr;
x:=d[(st+dr)shr 1];
repeat
while d[i]<x do
inc(i);
while d[j]>x do
dec(j);
if i<=j then
begin
tmp:=d[i];d[i]:=d[j];d[j]:=tmp;
inc(i);dec(j);
end;
until i>j;
if j>st then
qsort(st,j);
if i<dr then
qsort(i,dr);
end;
begin
assign(f,fin);
reset(f);
d[0]:=-1;
new(a);
lga:=0;
while not(eoln(f)) do
begin
read(f,ch);
inc(lga);
a^[lga]:=tr[ch];
end;
readln(f);
n:=1;lg:=0;pmax:=1;
while not(eoln(f)) do
begin
read(f,ch);
inc(lg);
cuv[lg]:=tr[ch];
pmax:=pmax*3;
end;
pmax:=pmax div 3;
p3:=pmax;
for i:=1 to lg do
begin
aux:=cuv[i];
inc(d[1],p3*aux);
p3:=p3 div 3;
end;
readln(f);
while not(eof(f)) do
begin
inc(n);
p3:=pmax;
for i:=1 to lg do
begin
read(f,ch);
aux:=tr[ch];
inc(d[n],aux*p3);
p3:=p3 div 3;
end;
readln(f);
end;
close(f);
assign(f,fout);
rewrite(f);
qsort(1,n);
c:=0;
p3:=pmax;
nn:=0;
for i:=1 to n do
if d[i]<>d[i-1] then
begin
inc(nn);
dd[nn]:=d[i];
end;
logmax:=0;
while 1 shl logmax<=nn do
inc(logmax);
dec(logmax);
for i:=1 to lg do
begin
aux:=a^[i];
aux:=aux*p3;
c:=c+aux;
p3:=p3 div 3;
end;
num:=0;
for i:=lg+1 to lga do
begin
if query(c) then
inc(num);
aux:=a^[i-lg];
aux:=aux*pmax;
dec(c,aux);
c:=c*3;
aux:=a^[i];
inc(c,aux);
end;
if query(c) then
inc(num);
writeln(f,num);
close(f);
end.