import sys

input = sys.stdin.buffer.readline



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

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



INF = 10 ** 15

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

dp[0][0] = 0



for a, b, c in ABC:

  for i in range(400, -1, -1):

    for j in range(400, -1, -1):

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

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



answer = INF

for i in range(1, 401):

  for j in range(1, 401):

    if dp[i][j] != INF and i / j == Ma / Mb:

      answer = min(answer, dp[i][j])

      

print((answer if answer != INF else -1))
import sys

input = sys.stdin.buffer.readline



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

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



sumA = sum([ABC[i][0] for i in range(N)])

sumB = sum([ABC[i][1] for i in range(N)])



INF = 10 ** 15

dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)]

dp[0][0] = 0



for a, b, c in ABC:

  for i in range(sumA, -1, -1):

    for j in range(sumB, -1, -1):

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

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



answer = INF

for i in range(1, sumA + 1):

  for j in range(1, sumB + 1):

    if dp[i][j] != INF and i / j == Ma / Mb:

      answer = min(answer, dp[i][j])

      

print((answer if answer != INF else -1))
import sys

input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(N)]
INF = 10**15
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(400, -1, -1):
        for j in range(400, -1, -1):
            if dp[i][j] != INF:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
answer = INF
for i in range(1, 401):
    for j in range(1, 401):
        if dp[i][j] != INF and i / j == Ma / Mb:
            answer = min(answer, dp[i][j])
print((answer if answer != INF else -1))

import sys

input = sys.stdin.buffer.readline
N, Ma, Mb = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(N)]
sumA = sum([ABC[i][0] for i in range(N)])
sumB = sum([ABC[i][1] for i in range(N)])
INF = 10**15
dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(sumA, -1, -1):
        for j in range(sumB, -1, -1):
            if dp[i][j] != INF:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
answer = INF
for i in range(1, sumA + 1):
    for j in range(1, sumB + 1):
        if dp[i][j] != INF and i / j == Ma / Mb:
            answer = min(answer, dp[i][j])
print((answer if answer != INF else -1))

+sumA = sum([ABC[i][0] for i in range(N)]) +sumB = sum([ABC[i][1] for i in range(N)]) -dp = [[INF for j in range(401)] for i in range(401)] +dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)] -    for i in range(400, -1, -1): -        for j in range(400, -1, -1): +    for i in range(sumA, -1, -1): +        for j in range(sumB, -1, -1): -for i in range(1, 401): -    for j in range(1, 401): +for i in range(1, sumA + 1): +    for j in range(1, sumB + 1):