#include<bits/stdc++.h>
using namespace std;

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001;
int N;
int x,y;
int a[111],b[111],c[111],d[111];

int dp[110][310][910];

signed main(){
    cin>>N>>x>>y;
    rep(i,N)cin>>a[i]>>b[i]>>c[i]>>d[i];

    fill_n(**dp,110*310*910,-INF);
    dp[0][x][300+y]=0;
    rep(i,N){
        rep(j,301){
            rep(k,901){
                if(dp[i][j][k]==-INF)continue;
                chmax(dp[i+1][j][k],dp[i][j][k]);
                if(j-a[i]>=0)chmax(dp[i+1][j-a[i]][k+b[i]],dp[i+1][j][k]);
                chmax(dp[i+1][j][k-c[i]],dp[i][j][k]+d[i]);
            }
        }
    }

    int ma=0;
    rep(i,x+1)reps(j,300,901)chmax(ma,dp[N][i][j]);
    cout<<ma<<endl;
    return 0;
}