object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, ma, mb = sc.nextInt()
  val (a, b, c) = Array.fill(n)((sc.nextInt(), sc.nextInt(), sc.nextInt())).unzip3
  val m = 10*n
  val dp = Array.fill(n+1, m+1, m+1)(Int.MaxValue/2)
  dp(0)(0)(0) = 0
  for {
    i <- 1 to n
    ca <- 0 to m
    cb <- 0 to m
  } {
    dp(i)(ca)(cb) = dp(i)(ca)(cb).min(dp(i-1)(ca)(cb))
    if (ca >= a(i-1) && cb >= b(i-1)) {
      dp(i)(ca)(cb) = dp(i-1)(ca)(cb).min(dp(i-1)(ca - a(i-1))(cb - b(i-1)) + c(i-1))
    }
  }
  var ans = Int.MaxValue
  for {
    ca <- 0 to m
    cb <- 0 to m
    if (ca != 0 || cb != 0) && ca * mb == cb * ma
  } {
    ans = ans.min(dp(n)(ca)(cb))
  }
  println(if (ans == Int.MaxValue/2) -1 else ans)
}
