Pagini recente » Cod sursa (job #1588843) | Cod sursa (job #2474447) | Cod sursa (job #1663990) | Cod sursa (job #2469554) | Cod sursa (job #153652)
Cod sursa(job #153652)
var n1,c1,n2,c2,n3,c3,i,s,aux,r:longint;
rez,t:int64;
function max(a,b:longint):longint;
begin
max:=a;
if b>a then
max:=b;
end;
begin
assign(input,'plus.in');reset(input);
assign(output,'plus.out');rewrite(output);
readln(s);
readln(n1,c1,n2,c2,n3,c3);
if c1=0 then
begin
if c2<>0 then
begin
aux:=n1;n1:=n2;n2:=aux;
aux:=c1;c1:=c2;c2:=aux;
end;
if (c3<>0) then
begin
aux:=n1;n1:=n3;n3:=aux;
aux:=c1;c1:=c3;c3:=aux;
end;
end;
if c2>c3 then
begin
aux:=n3;n3:=n2;n2:=aux;
aux:=c3;c3:=c2;c2:=aux;
end;
for i:=0 to n1 do
begin
r:=s-i*c1;
if c2=-1 then
begin
if (c3=-1)and(r<=0) then
begin
t:=abs(r)-max(abs(r)-n2,abs(r)-n3);
if (n2>=abs(r))and(n3>=abs(r)) then
t:=abs(r);
if t>=0 then
rez:=rez+t+1;
end;
if (c3=0) then
if (r<=0)and(abs(r)<=n2) then
rez:=rez+n3+1;
if (c3=1) then
begin
t:=n3-r;
if n2-abs(r)<t then
t:=n2;
if t>=0 then
rez:=rez+t+1;
end;
end;
if c2=0 then
begin
if c3=0 then
if r=0 then
rez:=rez+(n2+1)*(n3+1);
if c3=1 then
if (r>=0)and(r<=n3) then
rez:=rez+n2+1;
end;
if c2=1 then
if c3=1 then
if r>=0 then
begin
t:=(r-max(r-n2,r-n3));
if (n2>=abs(r))and(n3>=abs(r)) then
t:=r;
if t>=0 then
rez:=rez+t+1;
end;
end;
writeln(rez);
close(input);close(output);
end.