import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

from itertools import product

from copy import deepcopy

def resolve():

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

    ABC=[tuple(map(int,input().split())) for _ in range(n)]

    M=400



    dp=[[INF]*(M+1) for _ in range(M+1)]

    dp[0][0]=0



    for a,b,c in ABC:

        ndp=deepcopy(dp)

        for x,y in product(list(range(M+1)),repeat=2):

            if(x+a<=M and y+b<=M):

                ndp[x+a][y+b]=min(ndp[x+a][y+b],dp[x][y]+c)

        dp=ndp



    ans=INF

    for x,y in product(list(range(1,M+1)),repeat=2):

        if(x*mb==y*ma): ans=min(ans,dp[x][y])

    if(ans==INF): ans=-1

    print(ans)

resolve()
import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

from itertools import product

from copy import deepcopy

def resolve():

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

    ABC=[tuple(map(int,input().split())) for _ in range(n)]

    M=400



    dp=[[INF]*(M+1) for _ in range(M+1)]

    dp[0][0]=0



    for a,b,c in ABC:

        for x,y in product(list(range(M,-1,-1)),repeat=2):

            if(x+a<=M and y+b<=M):

                dp[x+a][y+b]=min(dp[x+a][y+b],dp[x][y]+c)



    ans=INF

    for x,y in product(list(range(1,M+1)),repeat=2):

        if(x*mb==y*ma): ans=min(ans,dp[x][y])

    if(ans==INF): ans=-1

    print(ans)

resolve()
import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
from itertools import product
from copy import deepcopy


def resolve():
    n, ma, mb = list(map(int, input().split()))
    ABC = [tuple(map(int, input().split())) for _ in range(n)]
    M = 400
    dp = [[INF] * (M + 1) for _ in range(M + 1)]
    dp[0][0] = 0
    for a, b, c in ABC:
        ndp = deepcopy(dp)
        for x, y in product(list(range(M + 1)), repeat=2):
            if x + a <= M and y + b <= M:
                ndp[x + a][y + b] = min(ndp[x + a][y + b], dp[x][y] + c)
        dp = ndp
    ans = INF
    for x, y in product(list(range(1, M + 1)), repeat=2):
        if x * mb == y * ma:
            ans = min(ans, dp[x][y])
    if ans == INF:
        ans = -1
    print(ans)


resolve()

import sys

sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
from itertools import product
from copy import deepcopy


def resolve():
    n, ma, mb = list(map(int, input().split()))
    ABC = [tuple(map(int, input().split())) for _ in range(n)]
    M = 400
    dp = [[INF] * (M + 1) for _ in range(M + 1)]
    dp[0][0] = 0
    for a, b, c in ABC:
        for x, y in product(list(range(M, -1, -1)), repeat=2):
            if x + a <= M and y + b <= M:
                dp[x + a][y + b] = min(dp[x + a][y + b], dp[x][y] + c)
    ans = INF
    for x, y in product(list(range(1, M + 1)), repeat=2):
        if x * mb == y * ma:
            ans = min(ans, dp[x][y])
    if ans == INF:
        ans = -1
    print(ans)


resolve()

-        ndp = deepcopy(dp) -        for x, y in product(list(range(M + 1)), repeat=2): +        for x, y in product(list(range(M, -1, -1)), repeat=2): -                ndp[x + a][y + b] = min(ndp[x + a][y + b], dp[x][y] + c) -        dp = ndp +                dp[x + a][y + b] = min(dp[x + a][y + b], dp[x][y] + c)