nmax, abmax, inf = 40, 10, 1000000



dp = [[[inf] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)] for _ in range(nmax + 1)]



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



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



for i in range(n):

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

  dpi = dp[i]

  dpi1 = dp[i + 1]

  for ca in range(0, 401):

    for cb in range(0, 401):

      if dpi[ca][cb] == inf:

        continue

      dpi1[ca][cb] = min(dpi1[ca][cb], dpi[ca][cb])

      dpi1[ca + a][cb + b] = min(dpi1[ca + a][cb + b], dpi[ca][cb] + c)



ans = inf

dpn = dp[n]

for ca in range(1, 401):

  for cb in range(1, 401):

    if ca * mb == cb * ma:

      ans = min(ans, dpn[ca][cb])



if ans == inf:

  ans = -1



print(ans)

INF = float('inf')

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

t = [[INF] * 401 for _ in range(401)]

t[0][0] = 0

for _ in range(n):

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

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

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

      if t[aa][bb] == INF:

        continue

      if t[a + aa][b + bb] > t[aa][bb] + c:

        t[a + aa][b + bb] = t[aa][bb] + c

result = INF

for a in range(400, 0, -1):

  for b in range(400, 0, -1):

    if a * mb == b * ma and t[a][b] < result:

      result = t[a][b]

if result == INF:

  result = -1

print(result)

nmax, abmax, inf = 40, 10, 1000000
dp = [
    [[inf] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)]
    for _ in range(nmax + 1)
]
n, ma, mb = list(map(int, input().split()))
dp[0][0][0] = 0
for i in range(n):
    a, b, c = list(map(int, input().split()))
    dpi = dp[i]
    dpi1 = dp[i + 1]
    for ca in range(0, 401):
        for cb in range(0, 401):
            if dpi[ca][cb] == inf:
                continue
            dpi1[ca][cb] = min(dpi1[ca][cb], dpi[ca][cb])
            dpi1[ca + a][cb + b] = min(dpi1[ca + a][cb + b], dpi[ca][cb] + c)
ans = inf
dpn = dp[n]
for ca in range(1, 401):
    for cb in range(1, 401):
        if ca * mb == cb * ma:
            ans = min(ans, dpn[ca][cb])
if ans == inf:
    ans = -1
print(ans)

INF = float("inf")
n, ma, mb = list(map(int, input().split()))
t = [[INF] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
    a, b, c = list(map(int, input().split()))
    for aa in range(400, -1, -1):
        for bb in range(400, -1, -1):
            if t[aa][bb] == INF:
                continue
            if t[a + aa][b + bb] > t[aa][bb] + c:
                t[a + aa][b + bb] = t[aa][bb] + c
result = INF
for a in range(400, 0, -1):
    for b in range(400, 0, -1):
        if a * mb == b * ma and t[a][b] < result:
            result = t[a][b]
if result == INF:
    result = -1
print(result)

-nmax, abmax, inf = 40, 10, 1000000 -dp = [ -    [[inf] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)] -    for _ in range(nmax + 1) -] +INF = float("inf") -dp[0][0][0] = 0 -for i in range(n): +t = [[INF] * 401 for _ in range(401)] +t[0][0] = 0 +for _ in range(n): -    dpi = dp[i] -    dpi1 = dp[i + 1] -    for ca in range(0, 401): -        for cb in range(0, 401): -            if dpi[ca][cb] == inf: +    for aa in range(400, -1, -1): +        for bb in range(400, -1, -1): +            if t[aa][bb] == INF: -            dpi1[ca][cb] = min(dpi1[ca][cb], dpi[ca][cb]) -            dpi1[ca + a][cb + b] = min(dpi1[ca + a][cb + b], dpi[ca][cb] + c) -ans = inf -dpn = dp[n] -for ca in range(1, 401): -    for cb in range(1, 401): -        if ca * mb == cb * ma: -            ans = min(ans, dpn[ca][cb]) -if ans == inf: -    ans = -1 -print(ans) +            if t[a + aa][b + bb] > t[aa][bb] + c: +                t[a + aa][b + bb] = t[aa][bb] + c +result = INF +for a in range(400, 0, -1): +    for b in range(400, 0, -1): +        if a * mb == b * ma and t[a][b] < result: +            result = t[a][b] +if result == INF: +    result = -1 +print(result)