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

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



INF = 10**9

dp = [[INF for j in range(401)] for i in range(401)]

dp[0][0] = 0

maxa = maxb = 0

for a,b,c in src:

    for ai in range(maxa,-1,-1):

        for bi in range(maxb,-1,-1):

            dp[ai+a][bi+b] = min(dp[ai+a][bi+b], dp[ai][bi] + c)

    maxa += a

    maxb += b



ans = INF

for i in range(1,401):

    if MA*i > 400 or MB*i > 400: break

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

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

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



INF = 10**9

MAX = 401

dp = [[INF] * MAX for i in range(MAX)]

dp[0][0] = 0

amax = bmax = 0

for a,b,n in src:

    for i in reversed(list(range(bmax+1))):

        for j in range(amax+1):

            if dp[i][j] == INF: continue

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

    amax += a

    bmax += b



ans = INF

for i in range(1,MAX):

    if i*MA >= MAX or i*MB >= MAX: break

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

print((-1 if ans == INF else ans))
N, MA, MB = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
INF = 10**9
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0
maxa = maxb = 0
for a, b, c in src:
    for ai in range(maxa, -1, -1):
        for bi in range(maxb, -1, -1):
            dp[ai + a][bi + b] = min(dp[ai + a][bi + b], dp[ai][bi] + c)
    maxa += a
    maxb += b
ans = INF
for i in range(1, 401):
    if MA * i > 400 or MB * i > 400:
        break
    ans = min(ans, dp[MA * i][MB * i])
print((-1 if ans == INF else ans))

N, MA, MB = list(map(int, input().split()))
src = [tuple(map(int, input().split())) for i in range(N)]
INF = 10**9
MAX = 401
dp = [[INF] * MAX for i in range(MAX)]
dp[0][0] = 0
amax = bmax = 0
for a, b, n in src:
    for i in reversed(list(range(bmax + 1))):
        for j in range(amax + 1):
            if dp[i][j] == INF:
                continue
            dp[i + b][j + a] = min(dp[i + b][j + a], dp[i][j] + n)
    amax += a
    bmax += b
ans = INF
for i in range(1, MAX):
    if i * MA >= MAX or i * MB >= MAX:
        break
    ans = min(ans, dp[i * MB][i * MA])
print((-1 if ans == INF else ans))

-dp = [[INF for j in range(401)] for i in range(401)] +MAX = 401 +dp = [[INF] * MAX for i in range(MAX)] -maxa = maxb = 0 -for a, b, c in src: -    for ai in range(maxa, -1, -1): -        for bi in range(maxb, -1, -1): -            dp[ai + a][bi + b] = min(dp[ai + a][bi + b], dp[ai][bi] + c) -    maxa += a -    maxb += b +amax = bmax = 0 +for a, b, n in src: +    for i in reversed(list(range(bmax + 1))): +        for j in range(amax + 1): +            if dp[i][j] == INF: +                continue +            dp[i + b][j + a] = min(dp[i + b][j + a], dp[i][j] + n) +    amax += a +    bmax += b -for i in range(1, 401): -    if MA * i > 400 or MB * i > 400: +for i in range(1, MAX): +    if i * MA >= MAX or i * MB >= MAX: -    ans = min(ans, dp[MA * i][MB * i]) +    ans = min(ans, dp[i * MB][i * MA])