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

src = []

sum_a = sum_b = 0

for i in range(N):

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

  src.append((a,b,c))

  sum_a += a

  sum_b += b



INF = 10**9

dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]

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



for i in range(N):

  ai,bi,ci = src[i]

  for a in range(sum_a+1 - ai):

    for b in range(sum_b+1 - bi):

      if dp[i][a][b] == INF: continue

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

      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)



ans = INF

n = 1

while True:

  a,b = n*MA,n*MB

  if a > sum_a or b > sum_b: break

  ans = min(ans, dp[N][a][b])

  n += 1



print((ans if ans != INF else -1))
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 = []
sum_a = sum_b = 0
for i in range(N):
    a, b, c = list(map(int, input().split()))
    src.append((a, b, c))
    sum_a += a
    sum_b += b
INF = 10**9
dp = [[[INF for b in range(sum_b + 1)] for a in range(sum_a + 1)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    ai, bi, ci = src[i]
    for a in range(sum_a + 1 - ai):
        for b in range(sum_b + 1 - bi):
            if dp[i][a][b] == INF:
                continue
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)
ans = INF
n = 1
while True:
    a, b = n * MA, n * MB
    if a > sum_a or b > sum_b:
        break
    ans = min(ans, dp[N][a][b])
    n += 1
print((ans if ans != INF else -1))

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))

-src = [] -sum_a = sum_b = 0 -for i in range(N): -    a, b, c = list(map(int, input().split())) -    src.append((a, b, c)) -    sum_a += a -    sum_b += b +src = [tuple(map(int, input().split())) for i in range(N)] -dp = [[[INF for b in range(sum_b + 1)] for a in range(sum_a + 1)] for i in range(N + 1)] -dp[0][0][0] = 0 -for i in range(N): -    ai, bi, ci = src[i] -    for a in range(sum_a + 1 - ai): -        for b in range(sum_b + 1 - bi): -            if dp[i][a][b] == INF: -                continue -            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b]) -            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci) +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 -n = 1 -while True: -    a, b = n * MA, n * MB -    if a > sum_a or b > sum_b: +for i in range(1, 401): +    if MA * i > 400 or MB * i > 400: -    ans = min(ans, dp[N][a][b]) -    n += 1 -print((ans if ans != INF else -1)) +    ans = min(ans, dp[MA * i][MB * i]) +print((-1 if ans == INF else ans))