N,MA,MB = list(map(int,input().split()))

ABC = [tuple(map(int,input().split())) for i in range(N)]



INF = float('inf')

from collections import defaultdict

dp = defaultdict(lambda: INF)

dp[(0,0)] = 0

for a,b,c in ABC:

    dp2 = defaultdict(lambda: INF)

    for (pa,pb),pc in list(dp.items()):

        dp2[(pa,pb)] = min(dp2[(pa,pb)], pc)

        dp2[(pa+a, pb+b)] = min(dp2[(pa+a, pb+b)], pc+c)

    dp = dp2



ans = INF

for i in range(1,401):

    ans = min(ans, dp[(MA*i, MB*i)])

print((-1 if ans==INF else ans))
N,MA,MB = list(map(int,input().split()))

ABC = [tuple(map(int,input().split())) for i in range(N)]



from collections import defaultdict

from copy import copy

d = defaultdict(lambda: float('inf'))

d[(0,0)] = 0

for a,b,c in ABC:

    d2 = copy(d)

    for (pa,pb),pc in list(d.items()):

        d2[(pa+a, pb+b)] = min(d2[(pa+a, pb+b)], pc+c)

    d = d2



ans = float('inf')

for (a,b),c in list(d.items()):

    if a==b==0: continue

    if a*MB == b*MA:

        ans = min(ans, c)

print((-1 if ans==float('inf') else ans))
N, MA, MB = list(map(int, input().split()))
ABC = [tuple(map(int, input().split())) for i in range(N)]
INF = float("inf")
from collections import defaultdict

dp = defaultdict(lambda: INF)
dp[(0, 0)] = 0
for a, b, c in ABC:
    dp2 = defaultdict(lambda: INF)
    for (pa, pb), pc in list(dp.items()):
        dp2[(pa, pb)] = min(dp2[(pa, pb)], pc)
        dp2[(pa + a, pb + b)] = min(dp2[(pa + a, pb + b)], pc + c)
    dp = dp2
ans = INF
for i in range(1, 401):
    ans = min(ans, dp[(MA * i, MB * i)])
print((-1 if ans == INF else ans))

N, MA, MB = list(map(int, input().split()))
ABC = [tuple(map(int, input().split())) for i in range(N)]
from collections import defaultdict
from copy import copy

d = defaultdict(lambda: float("inf"))
d[(0, 0)] = 0
for a, b, c in ABC:
    d2 = copy(d)
    for (pa, pb), pc in list(d.items()):
        d2[(pa + a, pb + b)] = min(d2[(pa + a, pb + b)], pc + c)
    d = d2
ans = float("inf")
for (a, b), c in list(d.items()):
    if a == b == 0:
        continue
    if a * MB == b * MA:
        ans = min(ans, c)
print((-1 if ans == float("inf") else ans))

-INF = float("inf") +from copy import copy -dp = defaultdict(lambda: INF) -dp[(0, 0)] = 0 +d = defaultdict(lambda: float("inf")) +d[(0, 0)] = 0 -    dp2 = defaultdict(lambda: INF) -    for (pa, pb), pc in list(dp.items()): -        dp2[(pa, pb)] = min(dp2[(pa, pb)], pc) -        dp2[(pa + a, pb + b)] = min(dp2[(pa + a, pb + b)], pc + c) -    dp = dp2 -ans = INF -for i in range(1, 401): -    ans = min(ans, dp[(MA * i, MB * i)]) -print((-1 if ans == INF else ans)) +    d2 = copy(d) +    for (pa, pb), pc in list(d.items()): +        d2[(pa + a, pb + b)] = min(d2[(pa + a, pb + b)], pc + c) +    d = d2 +ans = float("inf") +for (a, b), c in list(d.items()): +    if a == b == 0: +        continue +    if a * MB == b * MA: +        ans = min(ans, c) +print((-1 if ans == float("inf") else ans))