import java.util.Scanner

/**
 * Setの生成コストをもう少し揃える。
 */
fun main(args: Array<String>) {
    class Drug(a: Int, b: Int, val cost: Int, ma: Int, mb: Int) {
        val excess = a * mb - b * ma
    }

    data class Input(val n: Int, val ma: Int, val mb: Int, val drugs: List<Drug>)
    val (n, ma, mb, drugs) = Scanner(System.`in`).use<Scanner, Input> {
        val n = it.nextInt()
        val ma = it.nextInt()
        val mb = it.nextInt()
        val drugs: List<Drug> = Array(n) {n ->
            Drug(it.nextInt(), it.nextInt(), it.nextInt(), ma, mb)
        }.toList()

        Input(n, ma, mb, drugs)
    }

    var minimumCost = 4001
    var memo: MutableList<Set<Int>>
    var nextMemo: MutableList<Set<Int>> = Array(minimumCost, {mutableSetOf<Int>()}).toMutableList()
    nextMemo[0] = mutableSetOf(0)

    for (i in 0 until n) {
        memo = nextMemo
        nextMemo = mutableListOf(memo[0])
        for (cost in 1 until memo.size) {
            val next = if (cost - drugs[i].cost < 0) {
                memo[cost]
            } else {
                memo[cost - drugs[i].cost].map{it + drugs[i].excess}.toMutableSet().apply{ addAll(memo[cost]) }
            }

            nextMemo.add(next)
            if (0 in nextMemo[cost]) {
                minimumCost = cost
                break
            }
        }

    }

    println(if (minimumCost == 4001) -1 else minimumCost)
}
