import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val ma = sc.nextInt
  val mb = sc.nextInt

  val a = Array.ofDim[Int](n)
  val b = Array.ofDim[Int](n)
  val c = Array.ofDim[Int](n)

  for(i <- 0 until n) {
    a(i) = sc.nextInt
    b(i) = sc.nextInt
    c(i) = sc.nextInt
  }

  val maxWeight = 400

  val dp = Array.fill(n + 1, maxWeight + 1, maxWeight + 1)(Int.MaxValue)

  run()

  def run(): Unit = {
    dp(0)(0)(0) = 0

    for(i <- 0 until n) {
      for(wa <- 0 until maxWeight) {
        for(wb <- 0 until maxWeight) {
          if(dp(i)(wa)(wb) < Int.MaxValue) {
            dp(i + 1)(wa)(wb) = math.min(dp(i + 1)(wa)(wb), dp(i)(wa)(wb))
            dp(i + 1)(wa + a(i))(wb + b(i)) = math.min(dp(i + 1)(wa + a(i))(wb + b(i)), dp(i)(wa)(wb) + c(i))
          }
        }
      }
    }

    minValue(ma, mb) match {
      case Int.MaxValue => println(-1)
      case i => println(i)
    }
  }

  def minValue(wa: Int, wb: Int): Int = {
    if(wa > maxWeight || wb > maxWeight) Int.MaxValue
    else math.min(dp(n)(wa)(wb), minValue(wa + ma, wb + mb))
  }
}