#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  int x, y; cin >> x >> y;
  int dp[2][333][666]; minus(dp);
  int const OFFSET = 333;

  dp[0][x][y+OFFSET] = 0;

  rep(i, N) {
    int a, b, c, d; cin >> a >> b >> c >> d;
    rep(j, 333) rep(k, 666) {
      if(dp[i&1][j][k] < 0) { continue; }
      auto& next = dp[(i+1)&1];
      auto& curr = dp[i&1];
      maximize(next[j][k], curr[j][k]);
      if(j-a >= 0 && k+b < 666) {
        maximize(next[j-a][k+b], curr[j][k]);
      }
      if(k-c > 0) {
        maximize(next[j][k-c], curr[j][k] + d);
      }
    }
  }

  int ans = 0;

  rep(i, 333) REP(j, OFFSET, 666) {
    if(dp[N&1][i][j] < 0) { continue; }
    maximize(ans, dp[N&1][i][j]);
  }

  cout << ans << endl;

  return 0;
}