# coding:utf-8



import sys

# from collections import Counter, defaultdict



INF = float('inf')

MOD = 10 ** 9 + 7



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def II(): return int(sys.stdin.readline())

def SI(): return eval(input())





n, ma, mb = LI()

abc = [tuple(LI()) for _ in range(n)]

ab_max = n * 10 + 1



dp = [[[INF] * ab_max for _ in range(ab_max)] for _ in range(n + 1)]

dp[0][0][0] = 0





for i in range(n):

    ai, bi, ci = abc[i]

    for a in range(ab_max - ai):

        for b in range(ab_max - bi):

            if dp[i][a][b] == INF:

                continue

            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])

            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)





ans = INF

c = 1

while True:

    a, b = c * ma, c * mb

    if a >= ab_max or b >= ab_max:

        break

    ans = min(ans, dp[n][a][b])

    c += 1



print((ans if ans != INF else -1))

# coding:utf-8



import sys



INF = float('inf')

MOD = 10 ** 9 + 7



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def II(): return int(sys.stdin.readline())

def SI(): return eval(input())





n, ma, mb = LI()

src = []

a_max, b_max = 1, 1

for _ in range(n):

    a, b, c = LI()

    src.append((a, b, c))

    a_max += a

    b_max += b



dp = [[[INF] * b_max for _ in range(a_max)] for _ in range(n + 1)]

dp[0][0][0] = 0





for i in range(n):

    ai, bi, ci = src[i]

    for a in range(a_max - ai):

        for b in range(b_max - bi):

            if dp[i][a][b] == INF:

                continue

            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])

            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)





ans = INF

c = 1

while True:

    a, b = c * ma, c * mb

    if a >= a_max or b >= b_max:

        break

    ans = min(ans, dp[n][a][b])

    c += 1



print((ans if ans != INF else -1))

# coding:utf-8
import sys

# from collections import Counter, defaultdict
INF = float("inf")
MOD = 10**9 + 7


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def II():
    return int(sys.stdin.readline())


def SI():
    return eval(input())


n, ma, mb = LI()
abc = [tuple(LI()) for _ in range(n)]
ab_max = n * 10 + 1
dp = [[[INF] * ab_max for _ in range(ab_max)] for _ in range(n + 1)]
dp[0][0][0] = 0
for i in range(n):
    ai, bi, ci = abc[i]
    for a in range(ab_max - ai):
        for b in range(ab_max - bi):
            if dp[i][a][b] == INF:
                continue
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)
ans = INF
c = 1
while True:
    a, b = c * ma, c * mb
    if a >= ab_max or b >= ab_max:
        break
    ans = min(ans, dp[n][a][b])
    c += 1
print((ans if ans != INF else -1))

# coding:utf-8
import sys

INF = float("inf")
MOD = 10**9 + 7


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def II():
    return int(sys.stdin.readline())


def SI():
    return eval(input())


n, ma, mb = LI()
src = []
a_max, b_max = 1, 1
for _ in range(n):
    a, b, c = LI()
    src.append((a, b, c))
    a_max += a
    b_max += b
dp = [[[INF] * b_max for _ in range(a_max)] for _ in range(n + 1)]
dp[0][0][0] = 0
for i in range(n):
    ai, bi, ci = src[i]
    for a in range(a_max - ai):
        for b in range(b_max - bi):
            if dp[i][a][b] == INF:
                continue
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)
ans = INF
c = 1
while True:
    a, b = c * ma, c * mb
    if a >= a_max or b >= b_max:
        break
    ans = min(ans, dp[n][a][b])
    c += 1
print((ans if ans != INF else -1))

-# from collections import Counter, defaultdict -abc = [tuple(LI()) for _ in range(n)] -ab_max = n * 10 + 1 -dp = [[[INF] * ab_max for _ in range(ab_max)] for _ in range(n + 1)] +src = [] +a_max, b_max = 1, 1 +for _ in range(n): +    a, b, c = LI() +    src.append((a, b, c)) +    a_max += a +    b_max += b +dp = [[[INF] * b_max for _ in range(a_max)] for _ in range(n + 1)] -    ai, bi, ci = abc[i] -    for a in range(ab_max - ai): -        for b in range(ab_max - bi): +    ai, bi, ci = src[i] +    for a in range(a_max - ai): +        for b in range(b_max - bi): -    if a >= ab_max or b >= ab_max: +    if a >= a_max or b >= b_max: