fun main(arg: Array<String>) {
    val (N, Ma, Mb) = listOfInt()
    val ABC = Array(N) { listOfInt() }
    val INF = 1000009
    val ABMAX = 10
    val NABMAX = N * ABMAX
    val dp = Array(N + 1) { Array(NABMAX + 1) { IntArray(NABMAX + 1) { INF } } }
    dp[0][0][0] = 0
    for (n in 0 until N)
    for (a in 0 .. NABMAX)
    for (b in 0 .. NABMAX) {
        if (dp[n][a][b] == INF) continue
        dp[n + 1][a][b] = Math.min(dp[n + 1][a][b], dp[n][a][b])
        dp[n + 1][a + ABC[n][0]][b + ABC[n][1]] = 
            Math.min(dp[n + 1][a + ABC[n][0]][b + ABC[n][1]], dp[n][a][b] + ABC[n][2])
    }
    var ans = INF
    for (a in 1 .. NABMAX)
    for (b in 1 .. NABMAX) {
        if (Ma * b == Mb * a) ans = Math.min(ans, dp[N][a][b])
    }
    if (ans == INF) ans = -1
    println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
