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

INF=40*100+1

dp=[[INF for i in range(10*N+1)] for j in range(10*N+1)]

dp[0][0]=0

ans=INF

for p in range(N):

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

  for i in range(len(dp)-1,-1,-1):

    for j in range(len(dp[i])-1,-1,-1):

      if dp[i][j]!=INF:

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

        if (i+a)/(j+b)==Ma/Mb:

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

          

if ans==INF:

  print((-1))

else:

  print(ans)
# A,Bそれぞれの最大値は40 * 10である

# dp[i][j] = Aがiグラム、Bがjグラム含まれた薬品の最小コスト



import sys

readline = sys.stdin.readline



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

INF = 10 ** 10

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

dp[0][0] = 0



for _ in range(N):

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

  for i in range(len(dp) - 1, -1, -1):

    for j in range(len(dp[i]) - 1, -1, -1):

      if dp[i][j] == INF:

        continue

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



ans = INF

import math

for i in range(1, len(dp)):

  for j in range(1, len(dp)):

    g = math.gcd(i,j)

    if i // g == Ma and j // g == Mb:

      if ans > dp[i][j]:

        ans = dp[i][j]

      

if ans == INF:

  print((-1))

else:

  print(ans)
N, Ma, Mb = list(map(int, input().split()))
INF = 40 * 100 + 1
dp = [[INF for i in range(10 * N + 1)] for j in range(10 * N + 1)]
dp[0][0] = 0
ans = INF
for p in range(N):
    a, b, c = list(map(int, input().split()))
    for i in range(len(dp) - 1, -1, -1):
        for j in range(len(dp[i]) - 1, -1, -1):
            if dp[i][j] != INF:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
                if (i + a) / (j + b) == Ma / Mb:
                    ans = min(ans, dp[i + a][j + b])
if ans == INF:
    print((-1))
else:
    print(ans)

# A,Bそれぞれの最大値は40 * 10である
# dp[i][j] = Aがiグラム、Bがjグラム含まれた薬品の最小コスト
import sys

readline = sys.stdin.readline
N, Ma, Mb = list(map(int, readline().split()))
INF = 10**10
dp = [[INF] * (401) for i in range(401)]
dp[0][0] = 0
for _ in range(N):
    a, b, c = list(map(int, readline().split()))
    for i in range(len(dp) - 1, -1, -1):
        for j in range(len(dp[i]) - 1, -1, -1):
            if dp[i][j] == INF:
                continue
            dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
ans = INF
import math

for i in range(1, len(dp)):
    for j in range(1, len(dp)):
        g = math.gcd(i, j)
        if i // g == Ma and j // g == Mb:
            if ans > dp[i][j]:
                ans = dp[i][j]
if ans == INF:
    print((-1))
else:
    print(ans)

-N, Ma, Mb = list(map(int, input().split())) -INF = 40 * 100 + 1 -dp = [[INF for i in range(10 * N + 1)] for j in range(10 * N + 1)] +# A,Bそれぞれの最大値は40 * 10である +# dp[i][j] = Aがiグラム、Bがjグラム含まれた薬品の最小コスト +import sys + +readline = sys.stdin.readline +N, Ma, Mb = list(map(int, readline().split())) +INF = 10**10 +dp = [[INF] * (401) for i in range(401)] -ans = INF -for p in range(N): -    a, b, c = list(map(int, input().split())) +for _ in range(N): +    a, b, c = list(map(int, readline().split())) -            if dp[i][j] != INF: -                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c) -                if (i + a) / (j + b) == Ma / Mb: -                    ans = min(ans, dp[i + a][j + b]) +            if dp[i][j] == INF: +                continue +            dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c) +ans = INF +import math + +for i in range(1, len(dp)): +    for j in range(1, len(dp)): +        g = math.gcd(i, j) +        if i // g == Ma and j // g == Mb: +            if ans > dp[i][j]: +                ans = dp[i][j]