import copy

n,ma,mb=list(map(int,input().split()))

abc=[list(map(int,input().split())) for i in range(n)]

l=10*n

inf=float("inf")

data=[[inf]*(l+1) for i in range(l+1)]

data[0][0]=0

for u in abc:

    a,b,c=u

    h=copy.deepcopy(data)

    for i in range(l-a+1):

        for j in range(l-b+1):

            if data[i][j]!=inf:

                h[i+a][j+b]=min(h[i+a][j+b],data[i][j]+c)

    data=h

k=1

ans=inf

while ma*k<=l and mb*k<=l:

    if data[ma*k][mb*k]!=inf:

        ans=min(ans,data[ma*k][mb*k])

    k+=1

if ans!=inf:

    print(ans)

else:

    print((-1))
import numpy as np



n,ma,mb=list(map(int,input().split()))

L=10*n



dp=np.zeros((L+1,L+1),dtype="int64")

dq=np.zeros((L+1,L+1),dtype="int64")



inf=10**18

dp+=inf

dp[0][0]=0



for i in range(n):

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

    dq=dp.copy()

    dq[a:,b:]=np.minimum(dq[a:,b:],dp[:-a,:-b]+c)

    dp=dq

    

ans=inf

for i in range(1,401):

    if ma*i > L or mb*i > L:

        break

    ans=min(ans,dp[ma*i][mb*i])

if ans==inf:

    print((-1))

else:

    print(ans)
import copy

n, ma, mb = list(map(int, input().split()))
abc = [list(map(int, input().split())) for i in range(n)]
l = 10 * n
inf = float("inf")
data = [[inf] * (l + 1) for i in range(l + 1)]
data[0][0] = 0
for u in abc:
    a, b, c = u
    h = copy.deepcopy(data)
    for i in range(l - a + 1):
        for j in range(l - b + 1):
            if data[i][j] != inf:
                h[i + a][j + b] = min(h[i + a][j + b], data[i][j] + c)
    data = h
k = 1
ans = inf
while ma * k <= l and mb * k <= l:
    if data[ma * k][mb * k] != inf:
        ans = min(ans, data[ma * k][mb * k])
    k += 1
if ans != inf:
    print(ans)
else:
    print((-1))

import numpy as np

n, ma, mb = list(map(int, input().split()))
L = 10 * n
dp = np.zeros((L + 1, L + 1), dtype="int64")
dq = np.zeros((L + 1, L + 1), dtype="int64")
inf = 10**18
dp += inf
dp[0][0] = 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    dq = dp.copy()
    dq[a:, b:] = np.minimum(dq[a:, b:], dp[:-a, :-b] + c)
    dp = dq
ans = inf
for i in range(1, 401):
    if ma * i > L or mb * i > L:
        break
    ans = min(ans, dp[ma * i][mb * i])
if ans == inf:
    print((-1))
else:
    print(ans)

-import copy +import numpy as np -abc = [list(map(int, input().split())) for i in range(n)] -l = 10 * n -inf = float("inf") -data = [[inf] * (l + 1) for i in range(l + 1)] -data[0][0] = 0 -for u in abc: -    a, b, c = u -    h = copy.deepcopy(data) -    for i in range(l - a + 1): -        for j in range(l - b + 1): -            if data[i][j] != inf: -                h[i + a][j + b] = min(h[i + a][j + b], data[i][j] + c) -    data = h -k = 1 +L = 10 * n +dp = np.zeros((L + 1, L + 1), dtype="int64") +dq = np.zeros((L + 1, L + 1), dtype="int64") +inf = 10**18 +dp += inf +dp[0][0] = 0 +for i in range(n): +    a, b, c = list(map(int, input().split())) +    dq = dp.copy() +    dq[a:, b:] = np.minimum(dq[a:, b:], dp[:-a, :-b] + c) +    dp = dq -while ma * k <= l and mb * k <= l: -    if data[ma * k][mb * k] != inf: -        ans = min(ans, data[ma * k][mb * k]) -    k += 1 -if ans != inf: +for i in range(1, 401): +    if ma * i > L or mb * i > L: +        break +    ans = min(ans, dp[ma * i][mb * i]) +if ans == inf: +    print((-1)) +else: -else: -    print((-1))