import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
  val changers = Array.tabulate(n){_ ⇒
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    Changer(a, b, c, d)
  }
  val sumC = changers.map{_.c}.sum
  val memo = Array.fill(2){Array.fill(x + 1){Array.fill(changers.map{c ⇒ c.b + c.c}.sum + y + 1){-1L}}}
  memo(0)(x)(y + sumC) = 0L
  for ((changer, i) ← changers.zipWithIndex) {
    for (u ← memo(i%2).indices; f ← memo(i%2)(u).indices; if memo(i%2)(u)(f) != -1L) {
      if (memo((i+1)%2)(u)(f) < memo(i%2)(u)(f)) memo((i+1)%2)(u)(f) = memo(i%2)(u)(f)
      if (u - changer.a >= 0 && memo((i+1)%2)(u - changer.a)(f + changer.b) < memo(i%2)(u)(f)) {
        memo((i+1)%2)(u - changer.a)(f + changer.b) = memo(i%2)(u)(f)
      }
      if (memo((i+1)%2)(u)(f - changer.c) < memo(i%2)(u)(f) + changer.d){
        memo((i+1)%2)(u)(f - changer.c) = memo(i%2)(u)(f) + changer.d
      }
    }
  }
  println(memo(n % 2).map{a ⇒ (sumC until a.length).map(a).max}.max)
  case class Changer(a: Int, b: Int, c: Int, d: Int)
}
