# 入力

import sys

stdin = sys.stdin



def li(): return [int(x) for x in stdin.readline().split()]

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return [float(x) for x in stdin.readline().split()]

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(ns())

def nf(): return float(ns())



n, ma, mb = li()

a,b,c = list(), list(), list()

for _ in range(n):

    ai,bi,ci = li()

    a.append(ai)

    b.append(bi)

    c.append(ci)

    

INF = 10**5

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

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



for dr in range(n):

    for wa in range(10*n+1):

        for wb in range(10*n+1):

            dp[dr+1][wa][wb] = min(dp[dr][wa][wb], dp[dr][wa-a[dr]][wb-b[dr]] + c[dr])

            

ans = INF

k = 1

while k*ma <= 10*n and k*mb <= 10*n:

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

    k += 1

    

if ans == INF:

    print((-1))

else:

    print(ans)
import sys

stdin = sys.stdin

 

sys.setrecursionlimit(10**5) 

 

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



n,ma,mb = li()

drugs = []

for _ in range(n):

    drugs.append(tuple(li()))

    

dp = [[[10**10]*(401) for _ in range(401)] for _ in range(n+1)]

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



for i in range(n):

    ca, cb, cc = drugs[i]

    for aa in range(401):

        for bb in range(401):

            if 0 <= aa - ca <= 400 and 0 <= bb - cb <= 400:

                dp[i+1][aa][bb] = min(dp[i][aa-ca][bb-cb] + cc,

                                      dp[i][aa][bb])

                

            else:

                dp[i+1][aa][bb] = dp[i][aa][bb]



ans = 10**10     

for aa in range(1,401):

    for bb in range(1,401):

        if (aa/bb) == (ma/mb):

            ans = min(ans, dp[n][aa][bb])

            

if ans == 10**10:

    print((-1))

else:

    print(ans)
# 入力
import sys

stdin = sys.stdin


def li():
    return [int(x) for x in stdin.readline().split()]


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return [float(x) for x in stdin.readline().split()]


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(ns())


def nf():
    return float(ns())


n, ma, mb = li()
a, b, c = list(), list(), list()
for _ in range(n):
    ai, bi, ci = li()
    a.append(ai)
    b.append(bi)
    c.append(ci)
INF = 10**5
dp = [
    [[INF for _ in range(10 * n + 1)] for _ in range(10 * n + 1)] for _ in range(n + 1)
]
dp[0][0][0] = 0
for dr in range(n):
    for wa in range(10 * n + 1):
        for wb in range(10 * n + 1):
            dp[dr + 1][wa][wb] = min(
                dp[dr][wa][wb], dp[dr][wa - a[dr]][wb - b[dr]] + c[dr]
            )
ans = INF
k = 1
while k * ma <= 10 * n and k * mb <= 10 * n:
    ans = min(ans, dp[n][k * ma][k * mb])
    k += 1
if ans == INF:
    print((-1))
else:
    print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


n, ma, mb = li()
drugs = []
for _ in range(n):
    drugs.append(tuple(li()))
dp = [[[10**10] * (401) for _ in range(401)] for _ in range(n + 1)]
dp[0][0][0] = 0
for i in range(n):
    ca, cb, cc = drugs[i]
    for aa in range(401):
        for bb in range(401):
            if 0 <= aa - ca <= 400 and 0 <= bb - cb <= 400:
                dp[i + 1][aa][bb] = min(dp[i][aa - ca][bb - cb] + cc, dp[i][aa][bb])
            else:
                dp[i + 1][aa][bb] = dp[i][aa][bb]
ans = 10**10
for aa in range(1, 401):
    for bb in range(1, 401):
        if (aa / bb) == (ma / mb):
            ans = min(ans, dp[n][aa][bb])
if ans == 10**10:
    print((-1))
else:
    print(ans)

-# 入力 +sys.setrecursionlimit(10**5) -    return [int(x) for x in stdin.readline().split()] +    return list(map(int, stdin.readline().split())) -    return [float(x) for x in stdin.readline().split()] +    return list(map(float, stdin.readline().split())) -    return int(ns()) +    return int(stdin.readline()) -    return float(ns()) +    return float(stdin.readline()) -a, b, c = list(), list(), list() +drugs = [] -    ai, bi, ci = li() -    a.append(ai) -    b.append(bi) -    c.append(ci) -INF = 10**5 -dp = [ -    [[INF for _ in range(10 * n + 1)] for _ in range(10 * n + 1)] for _ in range(n + 1) -] +    drugs.append(tuple(li())) +dp = [[[10**10] * (401) for _ in range(401)] for _ in range(n + 1)] -for dr in range(n): -    for wa in range(10 * n + 1): -        for wb in range(10 * n + 1): -            dp[dr + 1][wa][wb] = min( -                dp[dr][wa][wb], dp[dr][wa - a[dr]][wb - b[dr]] + c[dr] -            ) -ans = INF -k = 1 -while k * ma <= 10 * n and k * mb <= 10 * n: -    ans = min(ans, dp[n][k * ma][k * mb]) -    k += 1 -if ans == INF: +for i in range(n): +    ca, cb, cc = drugs[i] +    for aa in range(401): +        for bb in range(401): +            if 0 <= aa - ca <= 400 and 0 <= bb - cb <= 400: +                dp[i + 1][aa][bb] = min(dp[i][aa - ca][bb - cb] + cc, dp[i][aa][bb]) +            else: +                dp[i + 1][aa][bb] = dp[i][aa][bb] +ans = 10**10 +for aa in range(1, 401): +    for bb in range(1, 401): +        if (aa / bb) == (ma / mb): +            ans = min(ans, dp[n][aa][bb]) +if ans == 10**10: