program eight;
var i,j,n:longint;
a,b,max:int64;
S,W:array[0..20]of longint;
M:array[1..20]of boolean;
function upint(x:extended):int64;
begin
if trunc(x)=x then exit(trunc(x)) else exit(trunc(x)+1);
end;
function LMC(x,y:int64):int64;
var a,b,c,d:int64;
begin
a:=x; b:=y;
d:=a*b; c:=a mod b;
while c<>0 do
begin
a:=b; b:=c;
c:=a mod b;
end;
exit(d div b);
end;
procedure search(x,y:longint);
var i:longint; p,q:int64; v:boolean;
begin
if W[0]=y then
begin
v:=false; q:=8;
for i:=1 to W[0] do
begin
q:=LMC(q,S[W[i]]);
if q>b then begin v:=true; break; end;
end;
if (not v) then
begin
p:=(b div q)-upint(a/q)+1;
if (y mod 2)=1 then max:=max-p else max:=max+p;
end;
end else
begin
if (n-x+1)>=(y-W[0]) then
begin
for i:=x to n do
if M[i]=false then
begin
W[0]+=1; W[W[0]]:=i; M[i]:=true;
search(i+1,y);
W[W[0]]:=0; W[0]-=1; M[i]:=false;
end;
end;
end;
end;
begin
assign(input,'eight.in'); reset(input);
assign(output,'eight.out'); rewrite(output);
readln(n);
for i:=1 to n do read(S[i]);
readln(a,b);
max:=(b div 8)-upint(a/8);
for i:=1 to n do
begin
for j:=1 to n do M[j]:=false;
for j:=0 to 20 do W[j]:=0;
search(1,i);
end;
writeln(max+1);
close(input); close(output);
end.