INF = float('inf')

MAXAB = 10

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

t = [[INF] * (n * MAXAB + 1) for _ in range(n * MAXAB + 1)]

t[0][0] = 0

for _ in range(n):

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

  for aa in range(n * MAXAB, -1, -1):

    for bb in range(n * MAXAB, -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(1, n * MAXAB + 1):

  for b in range(1, n * MAXAB + 1):

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

      result = t[a][b]

if result == INF:

  result = -1

print(result)

INF = float('inf')

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

ccmax = n * 10

t = [[INF] * (ccmax + 1) for _ in range(ccmax + 1)]

for _ in range(n):

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

  for aa in range(ccmax, 0, -1):

    taa = t[aa]

    for bb in range(ccmax, 0, -1):

      if taa[bb] == INF:

        continue

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

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

  if t[a][b] > c:

    t[a][b] = c

result = INF

for a in range(1, ccmax):

  ta = t[a]

  for b in range(1, ccmax):

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

      result = ta[b]

if result == INF:

  result = -1

print(result)

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

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

-MAXAB = 10 -t = [[INF] * (n * MAXAB + 1) for _ in range(n * MAXAB + 1)] -t[0][0] = 0 +ccmax = n * 10 +t = [[INF] * (ccmax + 1) for _ in range(ccmax + 1)] -    for aa in range(n * MAXAB, -1, -1): -        for bb in range(n * MAXAB, -1, -1): -            if t[aa][bb] == INF: +    for aa in range(ccmax, 0, -1): +        taa = t[aa] +        for bb in range(ccmax, 0, -1): +            if taa[bb] == INF: -            if t[a + aa][b + bb] > t[aa][bb] + c: -                t[a + aa][b + bb] = t[aa][bb] + c +            if t[a + aa][b + bb] > c + taa[bb]: +                t[a + aa][b + bb] = c + taa[bb] +    if t[a][b] > c: +        t[a][b] = c -for a in range(1, n * MAXAB + 1): -    for b in range(1, n * MAXAB + 1): -        if a * mb == b * ma and result > t[a][b]: -            result = t[a][b] +for a in range(1, ccmax): +    ta = t[a] +    for b in range(1, ccmax): +        if a * mb == b * ma and ta[b] < result: +            result = ta[b]