import fractions



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

a = [0] * (n + 1)

b = [0] * (n + 1)

c = [0] * (n + 1)

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

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



#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト

dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \

    for k in range(401)]



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

sa = [0] * (n + 1)

sb = [0] * (n + 1)



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

    for j in range(401):

        for k in range(401):

            if j < a[i] or k < b[i]:

                dp[k][j][i] = dp[k][j][i - 1]

            else:

                dp[k][j][i] = min(dp[k][j][i - 1], \

                    dp[k - b[i]][j - a[i]][i - 1] + c[i])



i = 1

ans = 10 ** 15

while True:

    if i * ma > 400 or i * mb > 400:

        break

    ans = min(ans, dp[i * mb][i * ma][n])

    i += 1



if ans == 10 ** 15:

    ans = -1



print(ans)



"""

import fractions



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

a = [0] * (n + 1)

b = [0] * (n + 1)

c = [0] * (n + 1)

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

    a[i], b[i], c[i] = map(int,input().split())



#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト

dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \

    for k in range(401)]



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

sa = [0] * (n + 1)

sb = [0] * (n + 1)



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

    sa[i] = sa[i - 1] + a[i]

    sb[i] = sb[i - 1] + b[i]



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

    for j in range(sa[i] + 1):

        for k in range(sb[i] + 1):

            if j < a[i] or k < b[i]:

                dp[k][j][i] = dp[k][j][i - 1]

            else:

                dp[k][j][i] = min(dp[k][j][i - 1], \

                    dp[k - b[i]][j - a[i]][i - 1] + c[i])



i = 1

ans = 10 ** 15

while True:

    if i * ma > 400 or i * mb > 400:

        break

    ans = min(ans, dp[i * mb][i * ma][n])

    i += 1



if ans == 10 ** 15:

    ans = -1



print(ans)

"""

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

a = [0] * (n + 1)

b = [0] * (n + 1)

c = [0] * (n + 1)

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

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



#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト

dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \

    for k in range(401)]



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

sa = [0] * (n + 1)

sb = [0] * (n + 1)



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

    sa[i] = sa[i - 1] + a[i]

    sb[i] = sb[i - 1] + b[i]



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

    for j in range(sa[i] + 1):

        for k in range(sb[i] + 1):

            if j < a[i] or k < b[i]:

                dp[k][j][i] = dp[k][j][i - 1]

            else:

                dp[k][j][i] = min(dp[k][j][i - 1], \

                    dp[k - b[i]][j - a[i]][i - 1] + c[i])



i = 1

ans = 10 ** 15

while True:

    if i * ma > 400 or i * mb > 400:

        break

    ans = min(ans, dp[i * mb][i * ma][n])

    i += 1



if ans == 10 ** 15:

    ans = -1



print(ans)
import fractions

n, ma, mb = list(map(int, input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int, input().split()))
# iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10**15 for i in range(n + 1)] for j in range(401)] for k in range(401)]
dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)
for i in range(1, n + 1):
    for j in range(401):
        for k in range(401):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], dp[k - b[i]][j - a[i]][i - 1] + c[i])
i = 1
ans = 10**15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1
if ans == 10**15:
    ans = -1
print(ans)
"""
import fractions
n, ma, mb = map(int,input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = map(int,input().split())
#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]
dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)
for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]
for i in range(1, n + 1):
    for j in range(sa[i] + 1):
        for k in range(sb[i] + 1):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])
i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1
if ans == 10 ** 15:
    ans = -1
print(ans)
"""

n, ma, mb = list(map(int, input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int, input().split()))
# iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10**15 for i in range(n + 1)] for j in range(401)] for k in range(401)]
dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)
for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]
for i in range(1, n + 1):
    for j in range(sa[i] + 1):
        for k in range(sb[i] + 1):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], dp[k - b[i]][j - a[i]][i - 1] + c[i])
i = 1
ans = 10**15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1
if ans == 10**15:
    ans = -1
print(ans)

-import fractions - -    for j in range(401): -        for k in range(401): +    sa[i] = sa[i - 1] + a[i] +    sb[i] = sb[i - 1] + b[i] +for i in range(1, n + 1): +    for j in range(sa[i] + 1): +        for k in range(sb[i] + 1): -""" -import fractions -n, ma, mb = map(int,input().split()) -a = [0] * (n + 1) -b = [0] * (n + 1) -c = [0] * (n + 1) -for i in range(1, n + 1): -    a[i], b[i], c[i] = map(int,input().split()) -#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト -dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \ -    for k in range(401)] -dp[0][0][0] = 0 -sa = [0] * (n + 1) -sb = [0] * (n + 1) -for i in range(1, n + 1): -    sa[i] = sa[i - 1] + a[i] -    sb[i] = sb[i - 1] + b[i] -for i in range(1, n + 1): -    for j in range(sa[i] + 1): -        for k in range(sb[i] + 1): -            if j < a[i] or k < b[i]: -                dp[k][j][i] = dp[k][j][i - 1] -            else: -                dp[k][j][i] = min(dp[k][j][i - 1], \ -                    dp[k - b[i]][j - a[i]][i - 1] + c[i]) -i = 1 -ans = 10 ** 15 -while True: -    if i * ma > 400 or i * mb > 400: -        break -    ans = min(ans, dp[i * mb][i * ma][n]) -    i += 1 -if ans == 10 ** 15: -    ans = -1 -print(ans) -"""