<Problem>
http://ntucoder.net/Problem/Details/3347
Uses Crt;
Var a,b,c,d:array[1..1000] of longint;
t,p,n,i,j,res:longint;
Begin
readln(n,t,p);
for i:=1 to n do read(a[i],b[i],c[i],d[i]);
for i:=1 to n do
for j:=1 to n do
if (t>=a[j]) and (p>=b[j]) and (a[j]>-1) and (b[j]>-1) then
begin
t:=t+c[j];
p:=p+d[j];
a[j]:=-1; b[j]:=-1;
inc(res);
end;
writeln(res);
readln;
End.