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



INF = 10 ** 8



lst = [[INF] * 401 for i in range(401)]

lst[0][0] = 0



for _ in range(N):

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

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

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

            if lst[i- a][j - b] == INF:

                pass

            else:

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



ans = INF

n = 400 // max(Ma, Mb)

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

    ans = min(ans, lst[Ma * i][Mb * i])



if ans == INF:

    print((-1))

else:

    print (ans)



# for i in range(7):

#     print (lst[i][:7])
#masoyさんのコード



import numpy as np



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

U = N * 10



dp = np.zeros((U + 1, U + 1), dtype = np.int64)

temp = np.zeros_like(dp)



INF = 10 ** 18

dp += INF

dp[0, 0] = 0



for _ in range(N):

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

    temp[:] = dp.copy()

    temp[a:, b:] = np.minimum(temp[a:, b:], dp[:-a, :-b] + c)

    dp = temp #毎回、一つ前の結果を残す



answer = INF

for t in range(1, 401):

    a = Ma * t

    b = Mb * t

    if max(a, b) >= U: #到達できない量に達したら終了

        break

    answer = min(answer, dp[a, b])



if answer == INF:

    answer = -1



print (answer)

N, Ma, Mb = list(map(int, input().split()))
INF = 10**8
lst = [[INF] * 401 for i in range(401)]
lst[0][0] = 0
for _ in range(N):
    a, b, c = list(map(int, input().split()))
    for i in range(400, a - 1, -1):
        for j in range(400, b - 1, -1):
            if lst[i - a][j - b] == INF:
                pass
            else:
                lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c)
ans = INF
n = 400 // max(Ma, Mb)
for i in range(1, n + 1):
    ans = min(ans, lst[Ma * i][Mb * i])
if ans == INF:
    print((-1))
else:
    print(ans)
# for i in range(7):
#     print (lst[i][:7])

# masoyさんのコード
import numpy as np

N, Ma, Mb = list(map(int, input().split()))
U = N * 10
dp = np.zeros((U + 1, U + 1), dtype=np.int64)
temp = np.zeros_like(dp)
INF = 10**18
dp += INF
dp[0, 0] = 0
for _ in range(N):
    a, b, c = list(map(int, input().split()))
    temp[:] = dp.copy()
    temp[a:, b:] = np.minimum(temp[a:, b:], dp[:-a, :-b] + c)
    dp = temp  # 毎回、一つ前の結果を残す
answer = INF
for t in range(1, 401):
    a = Ma * t
    b = Mb * t
    if max(a, b) >= U:  # 到達できない量に達したら終了
        break
    answer = min(answer, dp[a, b])
if answer == INF:
    answer = -1
print(answer)

+# masoyさんのコード +import numpy as np + -INF = 10**8 -lst = [[INF] * 401 for i in range(401)] -lst[0][0] = 0 +U = N * 10 +dp = np.zeros((U + 1, U + 1), dtype=np.int64) +temp = np.zeros_like(dp) +INF = 10**18 +dp += INF +dp[0, 0] = 0 -    for i in range(400, a - 1, -1): -        for j in range(400, b - 1, -1): -            if lst[i - a][j - b] == INF: -                pass -            else: -                lst[i][j] = min(lst[i][j], lst[i - a][j - b] + c) -ans = INF -n = 400 // max(Ma, Mb) -for i in range(1, n + 1): -    ans = min(ans, lst[Ma * i][Mb * i]) -if ans == INF: -    print((-1)) -else: -    print(ans) -# for i in range(7): -#     print (lst[i][:7]) +    temp[:] = dp.copy() +    temp[a:, b:] = np.minimum(temp[a:, b:], dp[:-a, :-b] + c) +    dp = temp  # 毎回、一つ前の結果を残す +answer = INF +for t in range(1, 401): +    a = Ma * t +    b = Mb * t +    if max(a, b) >= U:  # 到達できない量に達したら終了 +        break +    answer = min(answer, dp[a, b]) +if answer == INF: +    answer = -1 +print(answer)