G_MAX = 40*10

N_MAX = 40

INF = float('inf')



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

      for _ in range(N_MAX+1)]

N,Ma,Mb = list(map(int, input().split()))

a,b,c = [],[],[]

for _ in range(N):

    ai,bi,ci = list(map(int, input().split()))

    a.append(ai)

    b.append(bi)

    c.append(ci)



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

from math import isinf

for i in range(N):

    for ca in range(G_MAX+1):

        for cb in range(G_MAX+1):

            if isinf(dp[i][ca][cb]): continue

            dp[i+1][ca][cb] = min(dp[i+1][ca][cb],

                                 dp[i][ca][cb])

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

                                           dp[i][ca][cb]+c[i])

            

    

ans = INF

for ca in range(1,G_MAX+1):

    for cb in range(1,G_MAX+1):

        if ca*Mb==cb*Ma:

            ans = min(ans, dp[N][ca][cb])

            

if isinf(ans): ans = -1

print(ans)
from math import isinf



N, Ma, Mb = list(map(int, input().split()))

a = [0]*N

b = [0]*N

c = [0]*N

for i in range(N):

    a[i],b[i],c[i] = list(map(int, input().split()))



W_MAX = 40*10

dp = [[float('inf')]*(W_MAX+1) for _ in range(W_MAX+1)]

dp[0][0] = 0



for i in range(N):

    for wa in reversed(list(range(W_MAX+1))):

        for wb in reversed(list(range(W_MAX+1))):

            if isinf(dp[wa][wb]): continue

            if wa+a[i]<=W_MAX and wb+b[i]<=W_MAX:

                dp[wa+a[i]][wb+b[i]] = min(dp[wa+a[i]][wb+b[i]],

                                           dp[wa][wb]+c[i])



ans = float('inf')

for wa in range(1, W_MAX+1):

    for wb in range(1, W_MAX+1):

        if wa*Mb == wb*Ma:

            ans = min(ans, dp[wa][wb])



if isinf(ans): ans = -1

print(ans)
G_MAX = 40 * 10
N_MAX = 40
INF = float("inf")
dp = [[[INF] * (G_MAX + 1) for _ in range(G_MAX + 1)] for _ in range(N_MAX + 1)]
N, Ma, Mb = list(map(int, input().split()))
a, b, c = [], [], []
for _ in range(N):
    ai, bi, ci = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)
    c.append(ci)
dp[0][0][0] = 0
from math import isinf

for i in range(N):
    for ca in range(G_MAX + 1):
        for cb in range(G_MAX + 1):
            if isinf(dp[i][ca][cb]):
                continue
            dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb])
            dp[i + 1][ca + a[i]][cb + b[i]] = min(
                dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]
            )
ans = INF
for ca in range(1, G_MAX + 1):
    for cb in range(1, G_MAX + 1):
        if ca * Mb == cb * Ma:
            ans = min(ans, dp[N][ca][cb])
if isinf(ans):
    ans = -1
print(ans)

from math import isinf

N, Ma, Mb = list(map(int, input().split()))
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = list(map(int, input().split()))
W_MAX = 40 * 10
dp = [[float("inf")] * (W_MAX + 1) for _ in range(W_MAX + 1)]
dp[0][0] = 0
for i in range(N):
    for wa in reversed(list(range(W_MAX + 1))):
        for wb in reversed(list(range(W_MAX + 1))):
            if isinf(dp[wa][wb]):
                continue
            if wa + a[i] <= W_MAX and wb + b[i] <= W_MAX:
                dp[wa + a[i]][wb + b[i]] = min(
                    dp[wa + a[i]][wb + b[i]], dp[wa][wb] + c[i]
                )
ans = float("inf")
for wa in range(1, W_MAX + 1):
    for wb in range(1, W_MAX + 1):
        if wa * Mb == wb * Ma:
            ans = min(ans, dp[wa][wb])
if isinf(ans):
    ans = -1
print(ans)

-G_MAX = 40 * 10 -N_MAX = 40 -INF = float("inf") -dp = [[[INF] * (G_MAX + 1) for _ in range(G_MAX + 1)] for _ in range(N_MAX + 1)] -N, Ma, Mb = list(map(int, input().split())) -a, b, c = [], [], [] -for _ in range(N): -    ai, bi, ci = list(map(int, input().split())) -    a.append(ai) -    b.append(bi) -    c.append(ci) -dp[0][0][0] = 0 +N, Ma, Mb = list(map(int, input().split())) +a = [0] * N +b = [0] * N +c = [0] * N -    for ca in range(G_MAX + 1): -        for cb in range(G_MAX + 1): -            if isinf(dp[i][ca][cb]): +    a[i], b[i], c[i] = list(map(int, input().split())) +W_MAX = 40 * 10 +dp = [[float("inf")] * (W_MAX + 1) for _ in range(W_MAX + 1)] +dp[0][0] = 0 +for i in range(N): +    for wa in reversed(list(range(W_MAX + 1))): +        for wb in reversed(list(range(W_MAX + 1))): +            if isinf(dp[wa][wb]): -            dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]) -            dp[i + 1][ca + a[i]][cb + b[i]] = min( -                dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i] -            ) -ans = INF -for ca in range(1, G_MAX + 1): -    for cb in range(1, G_MAX + 1): -        if ca * Mb == cb * Ma: -            ans = min(ans, dp[N][ca][cb]) +            if wa + a[i] <= W_MAX and wb + b[i] <= W_MAX: +                dp[wa + a[i]][wb + b[i]] = min( +                    dp[wa + a[i]][wb + b[i]], dp[wa][wb] + c[i] +                ) +ans = float("inf") +for wa in range(1, W_MAX + 1): +    for wb in range(1, W_MAX + 1): +        if wa * Mb == wb * Ma: +            ans = min(ans, dp[wa][wb])