Dolphin plans to create a chemical substance C by mixing two substances A and B in a specific ratio. He needs to purchase chemicals from a local pharmacy to achieve this. Each chemical package contains a certain amount of A and B and is sold at a specific price. Dolphin must use all the contents of the purchased packages to create C. The task is to find the minimum amount of money required to generate C. If it's not possible to create C with any combination of packages, the output should be -1. The input consists of the number of chemicals available, the desired ratio of A to B, and the details of each chemical package. The output should indicate the minimum amount of money needed or -1 if it's not possible to create C.

# Buggy version:
from copy import deepcopy

def getval():
    n,ma,mb = map(int,input().split())
    p = [list(map(int,input().split())) for i in range(n)]
    return n,ma,mb,p 

def main(n,ma,mb,p):
    dp = [[[-1 for i in range(401)] for i in range(401)]]
    dp[0][0][0] = 0
    for i in range(n):
        temp = deepcopy(dp[-1])
        temp[0][0] = 0
        cur = p[i]
        prev = dp[-1]
        for a in range(401):
            for b in range(401):
                if cur[0]>a or cur[1]>b:
                    continue
                if prev[a-cur[0]][b-cur[1]]==-1:
                    continue
                elif prev[a][b]==-1:
                    temp[a][b] = prev[a-cur[0]][b-cur[1]] + cur[2]
                    #print(i,a,b,temp[a][b],prev[a-cur[0]][b-cur[1]])
                else:
                    temp[a][b] = min(prev[a][b], prev[a-cur[0]][b-cur[1]] + cur[2])
        #dp.append(temp)
    ans = -1
    for i in range(1,11):
        if i*ma>10 or i*mb>10:
            break
        if dp[n][i*ma][i*mb]!=-1:
            if ans==-1:
                ans = dp[n][i*ma][i*mb]
            else:
                ans = min(ans,dp[n][i*ma][i*mb])
    print(ans)
    print(dp[n])

if __name__=="__main__":
    n,ma,mb,p = getval()
    main(n,ma,mb,p)

# Fixed version:
from copy import deepcopy

def getval():
    n,ma,mb = map(int,input().split())
    p = [list(map(int,input().split())) for i in range(n)]
    return n,ma,mb,p 

def main(n,ma,mb,p):
    dp = [[[-1 for i in range(401)] for i in range(401)]]
    dp[0][0][0] = 0
    for i in range(n):
        temp = deepcopy(dp[-1])
        temp[0][0] = 0
        cur = p[i]
        prev = dp[-1]
        for a in range(401):
            for b in range(401):
                if cur[0]>a or cur[1]>b:
                    continue
                if prev[a-cur[0]][b-cur[1]]==-1:
                    continue
                elif prev[a][b]==-1:
                    temp[a][b] = prev[a-cur[0]][b-cur[1]] + cur[2]
                    #print(i,a,b,temp[a][b],prev[a-cur[0]][b-cur[1]])
                else:
                    temp[a][b] = min(prev[a][b], prev[a-cur[0]][b-cur[1]] + cur[2])
        dp.append(temp)
    ans = -1
    for i in range(1,401):
        if i*ma>400 or i*mb>400:
            break
        if dp[n][i*ma][i*mb]!=-1:
            if ans==-1:
                ans = dp[n][i*ma][i*mb]
            else:
                ans = min(ans,dp[n][i*ma][i*mb])
    print(ans)
    #print(dp[n])

if __name__=="__main__":
    n,ma,mb,p = getval()
    main(n,ma,mb,p)

# Buggy version:
N, Ma, Mb = map(int,input().split())
L = []
for _ in range(N):
    L.append( list(map(int,input().split())) )
dp = [[[10**10 for _ in range(601)] for _ in range(601)] for _ in range(N+10)]
dp[0][0][0] = 0

for l in range(N):
    for i in range(200):
        for j in range(200):
            dp[l+1][i][j] = min(dp[l+1][i][j],dp[l][i][j])
            dp[l+1][i+L[l][0]][j+L[l][1]] = min(dp[l+1][i+L[l][0]][j+L[l][1]],dp[l][i][j] + L[l][2])


ans = 10**10
for i in range(1,10000):
    try: ans = min(ans, dp[N+1][Ma*i][Mb*i])
    except: pass
if ans == 10**10: print(-1)
else: print(ans)





# Fixed version:
N, Ma, Mb = map(int,input().split())
L = []
for _ in range(N):
    L.append( list(map(int,input().split())) )
dp = [[[10**10 for _ in range(601)] for _ in range(601)] for _ in range(N+10)]
dp[0][0][0] = 0

for l in range(N):
    for i in range(200):
        for j in range(200):
            dp[l+1][i][j] = min(dp[l+1][i][j],dp[l][i][j])
            dp[l+1][i+L[l][0]][j+L[l][1]] = min(dp[l+1][i+L[l][0]][j+L[l][1]],dp[l][i][j] + L[l][2])


ans = 10**10
for i in range(1,10000):
    try: ans = min(ans, dp[N][Ma*i][Mb*i])
    except: pass
if ans == 10**10: print(-1)
else: print(ans)

# Buggy version:
def main():
    N, Ma, Mb = map(int, input().split())
    yakuhin = []
    sa = 0
    sb = 0
    for i in range(N):
        yakuhin.append(list(map(int, input().split())))
        sa += yakuhin[i][0]
        sb += yakuhin[i][1]
    
    INF = 10**15
    DP = [[[INF for _ in range(sb+1)] for _ in range(sa+1)] for _ in range(N+1)]
    DP[0][0][0] = 0
    
    for i in range(N):
        for j in range(sa+1):
            for k in range(sb+1):
                if(j >= yakuhin[i][0] and k >= yakuhin[i][1]):
                    DP[i+1][j][k] = min(DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]], DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]]+yakuhin[i][2])
                else:
                    DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])
        
    ans = INF
    for i in range(1, N):
        for j in range(1, sa+1):
            for k in range(1, sb+1):
                if(j*Mb == k*Ma):
                    ans = min(ans, DP[i][j][k])    
        
    print(ans if ans != INF else -1)
    
main()

# Fixed version:
def main():
    N, Ma, Mb = map(int, input().split())
    yakuhin = []
    sa = 0
    sb = 0
    for i in range(N):
        yakuhin.append(list(map(int, input().split())))
        sa += yakuhin[i][0]
        sb += yakuhin[i][1]
    
    INF = 10**15
    DP = [[[INF for _ in range(sb+1)] for _ in range(sa+1)] for _ in range(N+1)]
    
    for i in range(N):
        DP[i][0][0] = 0
    
    for i in range(N):
        for j in range(sa+1):
            for k in range(sb+1):
                if(j >= yakuhin[i][0] and k >= yakuhin[i][1]):
                    DP[i+1][j][k] = min(DP[i][j][k], DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]]+yakuhin[i][2])
                else:
                    DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])
        
    ans = INF
    for i in range(1, N+1):
        for j in range(1, sa+1):
            for k in range(1, sb+1):
                if(j*Mb == k*Ma):
                    ans = min(ans, DP[i][j][k])    
        
    print(ans if ans != INF else -1)
    
main()

# Buggy version:
N, Ma, Mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(N)]

inf = float('inf')
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]

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

for i in range(N - 1):
    for j in range(401):
        for k in range(401):
            if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
                dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2])
ans = inf
for a in range(401):
    if a % Ma == 0:
        b = a // Ma * Mb
        if b <= 401:
            ans = min(ans, dp[N][a][b])
if ans == inf:
    ans = -1
print(ans)


# Fixed version:
N, Ma, Mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(N)]

inf = float('inf')
dp = [[[inf] * 401 for _ in range(401)] for _ in range(N + 1)]

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

for i in range(N):
    for j in range(401):
        for k in range(401):
            dp[i + 1][j][k] = dp[i][j][k]
            if j - abc[i][0] >= 0 and k - abc[i][1] >= 0:
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - abc[i][0]][k - abc[i][1]] + abc[i][2])
ans = inf
for a in range(1, 401):
    for b in range(1, 401):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans == inf:
    ans = -1
print(ans)

# Buggy version:
import sys
input = sys.stdin.buffer.readline
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401-a):
        for k in range(401-b):
            ni=i+1
            dp[ni][j][k]=min(dp[ni][j][k], dp[i][j][k])
            dp[ni][nj][nk]=min(dp[i][j][k]+c,dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>400:
        break
    if mb*i>400:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)

# Fixed version:
import sys
input = sys.stdin.buffer.readline
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401-a):
        for k in range(401-b):
            ni=i+1
            nj=j+a
            nk=k+b
            dp[ni][j][k]=min(dp[ni][j][k], dp[i][j][k])
            dp[ni][nj][nk]=min(dp[i][j][k]+c,dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>400:
        break
    if mb*i>400:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)

# Buggy version:
n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

INF = 40 * 100 + 1
ab_max = 10 * n

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

for i, (a, b, c) in enumerate(abc, 1):
    for j in range(ab_max + 1):
        for k in range(ab_max + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j - a >= 0 and k - b >= 0:
                if dp[i-1][j-a][k-b] != INF:
                    dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a][k-b] + c)


ans = INF
for j in range(1, ab_max + 1):
    for k in range(1, ab_max + 1):
        if j * mb == k * ma:
            ans = min(ans, dp[n][j][k])

if ans == INF:
    ans = -1

print(ans)
print(*dp[n], sep="\n")

# Fixed version:
n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

INF = 40 * 100 + 1
ab_max = 10 * n

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

for i, (a, b, c) in enumerate(abc, 1):
    for j in range(ab_max + 1):
        for k in range(ab_max + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j - a >= 0 and k - b >= 0:
                if dp[i-1][j-a][k-b] != INF:
                    dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a][k-b] + c)


ans = INF
for j in range(1, ab_max + 1):
    for k in range(1, ab_max + 1):
        if j * mb == k * ma:
            ans = min(ans, dp[n][j][k])

if ans == INF:
    ans = -1

print(ans)

# Buggy version:
import numpy as np
n, ma, mb = map(int, input().split())
r = 10 * n + 6
inf = 10**5
dp = np.full((n+1, r, r), inf)
dp[0][0][0] = 0
for i in range(n):
    a, b, c = map(int, input().split())
    for j in range(r):
        for k in range(r):
            if j + a < r and k + b < r:
                dp[i+1][j+a][k+b] = min(
                    dp[i][j][k] + c, dp[i][j+a][k+b]
                )
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

ans = inf
x, y = 0, 0
for i in range(1, n+1):
    while True:
        x += ma
        y += mb
        if x < r and y < r:
            ans = min(ans, dp[i][x][y])
        else:
            break
if ans == inf:
    print(-1)
else:
    print(int(ans))

# Fixed version:
import numpy as np
n, ma, mb = map(int, input().split())
r = 10 * n + 6
inf = 10**5
dp = np.full((n+1, r, r), inf)
dp[0][0][0] = 0
for i in range(n):
    a, b, c = map(int, input().split())
    dp[i+1][a:, b:] = np.minimum(
        dp[i][:r-a, :r-b] + c, dp[i][a:, b:]
    )
    dp[i+1] = np.minimum(dp[i+1], dp[i])

ans = inf
x, y = 0, 0
while True:
    x += ma
    y += mb
    if x < r and y < r:
        ans = min(ans, dp[n][x][y])
    else:
        break
if ans == inf:
    print(-1)
else:
    print(int(ans))

# Buggy version:
N,Ma,Mb = map(int,input().split())
dp = [[[10**9 for i in range(400)] for j in range(400)] for k in range(N+1)]
dp[0][0][0] = 0
for i in range(1,N+1):
    a,b,c = map(int,input().split())
    for j in range(401):
        for k in range(401):
            if j < a:
                d[i][j][k] = d[i-1][j][k]
            else:
                if k < b:
                    d[i][j][k] = d[i-1][j][k]
                else:
                    d[i][j][k] = min(d[i-1][j][k],d[i-1][j-a][k-b] + c)
m = max(Ma,Mb)
import math
n = math.floor(400 / m)
ans = 10**9
for i in range(n):
    x = Ma*i
    y = Mb*i
    ans = min(dp[N][x][y])
print(ans)

# Fixed version:
N,Ma,Mb = map(int,input().split())
dp = [[[10**9 for i in range(401)] for j in range(401)] for k in range(N+1)]
dp[0][0][0] = 0
for i in range(1,N+1):
    a,b,c = map(int,input().split())
    for j in range(401):
        for k in range(401):
            if j < a:
                dp[i][j][k] = dp[i-1][j][k]
            else:
                if k < b:
                    dp[i][j][k] = dp[i-1][j][k]
                else:
                    dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a][k-b] + c)
m = max(Ma,Mb)
import math
n = math.floor(400 / m)
ans = 10**9
for i in range(1,400):
    x = Ma*i
    y = Mb*i
    if x > 400:
        break
    if y > 400:
        break
    ans = min(dp[N][x][y],ans)
if ans == 10**9:
    print(-1)
    quit()
print(ans)

# Buggy version:
n, ma, mb = [int(i) for i in input().split()]
lst = [[int(i) for i in input().split()] for _ in range(n)]
lst.sort(key=lambda x: x[2])

def push(k,v):
    if k in dic:
        dic[k] = min(dic[k],v)
    else:
        dic[k] = v


for i in lst:
    k, v = i[0] * mb - i[1] * ma, i[2]
    l = [[j, dic[j]] for j in dic]
    for item in l:
        push(item[0] + k, item[1] + v)
    push(k, v)

print(dic[0] if 0 in dic else '-1')

# Fixed version:
n, ma, mb = [int(i) for i in input().split()]
lst = [[int(i) for i in input().split()] for _ in range(n)]
lst.sort(key=lambda x: x[2])
dic = {}
def push(k,v):
    if k in dic:
        dic[k] = min(dic[k],v)
    else:
        dic[k] = v


for i in lst:
    k, v = i[0] * mb - i[1] * ma, i[2]
    l = [[j, dic[j]] for j in dic]
    for item in l:
        push(item[0] + k, item[1] + v)
    push(k, v)

print(dic[0] if 0 in dic else '-1')

# Buggy version:
N, Ma, Mb = 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 = map(int, input().split())
    for i in range(a, 401):
        for j in range(b, 401):
            if lst[i][j] == 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)

# Fixed version:
N, Ma, Mb = 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 = 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])

# Buggy version:
inf = float("inf")
N, Ma, Mb = map(int, input().split())
ABC = []
for _ in range(N):
    a, b, c = map(int, input().split())
    ABC.append((a, b, c))
dp = [[inf] * 420 for _ in range(420)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(410):
        for j in range(410):
            if dp[i][j] < inf:
                dp[i+a][j+b] = min(dp[i+a][j+b], dp[i][j] + c)
ans = inf
n = 1
while max(Ma * n, Mb * n) < 420:
    print(Ma * n, Mb * n)
    ans = min(ans, dp[Ma * n][Mb * n])
    n += 1
print(ans if ans < inf else -1)


# Fixed version:
inf = float("inf")
N, Ma, Mb = map(int, input().split())
ABC = []
for _ in range(N):
    a, b, c = map(int, input().split())
    ABC.append((a, b, c))
dp = [[inf] * 420 for _ in range(420)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(410, -1, -1):
        for j in range(410, -1, -1):
            if dp[i][j] < inf:
                dp[i+a][j+b] = min(dp[i+a][j+b], dp[i][j] + c)
ans = inf
n = 1
while max(Ma * n, Mb * n) < 420:
    ans = min(ans, dp[Ma * n][Mb * n])
    n += 1
print(ans if ans < inf else -1)

# Buggy version:
n,ma,mb=map(int,input().split())
ab=[[[10**6]*401 for _ in range(401)] for _ in range(n+1)]
ab[0][0][0]=0

for p in range(1,n+1):
    a,b,c=map(int,input().split())
    for i in range(400):
        for j in range(400):
            if i+a<=400 and j+b<=400:
                ab[p][i+a][j+b]=min(ab[p][i+a][j+b],ab[p-1][i][j]+c)

ans=10**6-1
for i in range(401):
    for j in range(401):
        if i!=0 and j!=0:
            if i*mb==j*ma:
                ans=min(ans,ab[n][i][j])

if ans==10**6-1:
    print(-1)
else:
    print(ans)

# Fixed version:
n,ma,mb=map(int,input().split())
ab=[[[10**6]*401 for _ in range(401)] for _ in range(n+1)]
ab[0][0][0]=0

for p in range(1,n+1):
    a,b,c=map(int,input().split())
    for i in range(400):
        for j in range(400):
            ab[p][i][j]=min(ab[p][i][j],ab[p-1][i][j])
            if i+a<=400 and j+b<=400:
                ab[p][i+a][j+b]=min(ab[p][i+a][j+b],ab[p-1][i][j]+c)

ans=10**6-1
for i in range(401):
    for j in range(401):
        if i!=0 and j!=0:
            if i*mb==j*ma:
                ans=min(ans,ab[n][i][j])

if ans==10**6-1:
    print(-1)
else:
    print(ans)

# Buggy version:
def main():

    N, Ma, Mb = map(int, input().split())
    drug = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        drug.append([a, b, c])

    cur = dict()
    cur[(0, 0)] = 0
    for i in range(N):
        temp = cur.copy()
        for p in cur:
            a, b = p[0]+drug[i][0], p[1]+drug[i][1]

            if (a, b) not in temp:
                temp[(a, b)] = cur[p] + drug[i][2]
            else:
                temp[(a, b)] = min(temp[(a, b)], cur[p]+drug[i][2])
        cur = temp

    # print(cur)
    min_c = float('inf')
    for p in cur:
        if p != (0, 0) and p[0]*Mb == p[1]*Ma:
            min_c = min(min_c, cur[p])
    if min_c == float('inf'):
        return -1
    else:
        return min_c


# Fixed version:
def main():

    N, Ma, Mb = map(int, input().split())
    drug = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        drug.append([a, b, c])

    cur = dict()
    cur[(0, 0)] = 0
    for i in range(N):
        temp = cur.copy()
        for p in cur:
            a, b = p[0]+drug[i][0], p[1]+drug[i][1]

            if (a, b) not in temp:
                temp[(a, b)] = cur[p] + drug[i][2]
            else:
                temp[(a, b)] = min(temp[(a, b)], cur[p]+drug[i][2])
        cur = temp

    # print(cur)
    min_c = float('inf')
    for p in cur:
        if p != (0, 0) and p[0]*Mb == p[1]*Ma:
            min_c = min(min_c, cur[p])
    if min_c == float('inf'):
        return -1
    else:
        return min_c

if __name__ == '__main__':
    print(main())

# Buggy version:
import sys
inf = float('inf')
n, ma, mb = map(int, input().split())
t = [[inf] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
  a, b, c = map(int, input().split())
  for aa in range(400, 0, -1):
    for bb in range(400, 0, -1):
      if t[aa][bb] == inf:
        continue
      if t[a + aa][b + bb] > c + t[aa][bb]:
        t[a + aa][b + bb] = c + t[aa][bb]
result = inf
for a in range(400, 0, -1):
  for b in range(400, 0, -1):
    if a * mb == b * ma and t[a][b] < result:
      result = t[a][b]
if result == inf:
  print(-1)
else:
  print(result)


# Fixed version:
import sys
inf = float('inf')
n, ma, mb = map(int, input().split())
t = [[inf] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
  a, b, c = map(int, input().split())
  for aa in range(400, -1, -1):
    for bb in range(400, -1, -1):
      if t[aa][bb] == inf:
        continue
      if t[a + aa][b + bb] > c + t[aa][bb]:
        t[a + aa][b + bb] = c + t[aa][bb]
result = inf
for a in range(400, 0, -1):
  for b in range(400, 0, -1):
    if a * mb == b * ma and t[a][b] < result:
      result = t[a][b]
if result == inf:
  print(-1)
else:
  print(result)

# Buggy version:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,A,B = [int(i) for i in readline().split()]
abc = [[int(i) for i in readline().split()] for j in range(n)]

ans = 10**9

d = {0:0}
for i in range(n):
    nd = {}
    a,b,c = abc[i]
    for amari,yen in d.items():
        if amari in nd:
            nd[amari] = min(nd[amari],yen)
        else:
            nd[amari] = yen

        yen += c
        amari += a*B-b*A
        if amari == 0 and yen != 0:
            ans = min(ans,yen)
        elif amari in nd:
            nd[amari] = min(nd[amari],yen)
        else:
            nd[amari] = yen
    d = nd
#    print(d,nd)

print(ans)





# Fixed version:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,A,B = [int(i) for i in readline().split()]
abc = [[int(i) for i in readline().split()] for j in range(n)]

ans = 10**9

d = {0:0}
for i in range(n):
    nd = {}
    a,b,c = abc[i]
    for amari,yen in d.items():
        if amari in nd:
            nd[amari] = min(nd[amari],yen)
        else:
            nd[amari] = yen

        yen += c
        amari += a*B-b*A
        if amari == 0 and yen != 0:
            ans = min(ans,yen)
        elif amari in nd:
            nd[amari] = min(nd[amari],yen)
        else:
            nd[amari] = yen
    d = nd
#    print(d,nd)

if ans == 10**9:
    print(-1)
else:
    print(ans)

# Buggy version:
N, Ma, Mb = map(int, input().split())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())

INF = 10 ** 5
nums = 7

dp = [[[INF for _ in range(nums)] for _ in range(nums)] for _ in range(N+1)]

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

for i in range(N):
    for sum_a in range(nums):
        for sum_b in range(nums):
            if dp[i][sum_a][sum_b] == INF:
                continue
            dp[i+1][sum_a+a[i]][sum_b+b[i]] = min(dp[i+1][sum_a+a[i]][sum_b+b[i]], dp[i][sum_a][sum_b] + c[i])
            dp[i+1][sum_a][sum_b] = min(dp[i+1][sum_a][sum_b], dp[i][sum_a][sum_b])
            #dp[i+1][sum_a+a[i]][sum_b+b[i]] = min(dp[i+1][sum_a+a[i]][sum_b+b[i]], dp[i][sum_a][sum_b] + c[i])
            #print(i, dp[i][sum_a][sum_b], sum_a, sum_b)


res = INF
for i in range(1, nums):
    for j in range(1, nums):
        if i * Mb == j * Ma:
            res = min(res, dp[N][i][j])

if res == INF:
    res = -1

print(res)


# Fixed version:
N, Ma, Mb = map(int, input().split())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())

INF = 10 ** 5
nums = 401

dp = [[[INF for _ in range(nums+100)] for _ in range(nums+100)] for _ in range(N+1)]

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

for i in range(N):
    for sum_a in range(nums):
        for sum_b in range(nums):
            #if dp[i][sum_a][sum_b] == INF:
            #    continue
            dp[i+1][sum_a+a[i]][sum_b+b[i]] = min(dp[i+1][sum_a+a[i]][sum_b+b[i]], dp[i][sum_a][sum_b] + c[i])
            dp[i+1][sum_a][sum_b] = min(dp[i+1][sum_a][sum_b], dp[i][sum_a][sum_b])
            #dp[i+1][sum_a+a[i]][sum_b+b[i]] = min(dp[i+1][sum_a+a[i]][sum_b+b[i]], dp[i][sum_a][sum_b] + c[i])
            #print(i, dp[i][sum_a][sum_b], sum_a, sum_b)


res = INF
for i in range(1, nums):
    for j in range(1, nums):
        if i * Mb == j * Ma:
            res = min(res, dp[N][i][j])

if res == INF:
    res = -1

print(res)

# Buggy version:
from fractions import gcd

inf = float('inf')

N,Ma,Mb = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(N)]

# dp[i][j][k]: i番目までみてj(g), k(g)となるような最小予算
dp = [[[inf]*401 for _ in range(401)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    a,b,c = abc[i]
    for j in range(401):
        for k in range(401):
            if j - a >= 0 and k - b >= 0:
                dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a][k-b] + c)
            else:
                dp[i+1][j][k] = dp[i][j][k]

ans = inf

for j in range(1,401):
    for k in range(1,401):
        G = gcd(j,k)
        if (j//G, k//G) == (Ma, Mb):
            ans = min(ans, dp[N][j][k])

if ans == inf:
    ans = -1
print(ans)

# Fixed version:
inf = float('inf')

N,Ma,Mb = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(N)]

# dp[i][j][k]: i番目までみてj(g), k(g)となるような最小予算
dp = [[[inf]*401 for _ in range(401)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    a,b,c = abc[i]
    for j in range(401):
        for k in range(401):
            if j - a >= 0 and k - b >= 0:
                dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a][k-b] + c)
            else:
                dp[i+1][j][k] = dp[i][j][k]

ans = inf

for j in range(1,401):
    for k in range(1,401):
        if j * Mb == Ma * k:
            ans = min(ans, dp[N][j][k])

if ans == inf:
    ans = -1
print(ans)

# Buggy version:
n,ma,mb=map(int,input().split())
inf=10**4
A=[]
append=A.append
for i in range(n):
  a,b,c=map(int,input().split())
  append([a,b,c])
DP=[[[inf]*(10*n+1) for _ in range(10*n+1)] for _ in range(n+1)]
DP[0][0][0]=0
for i in range(n):
  a,b,c=A[i][0],A[i][1],A[i][2]
  for j in range(10*(i+1)+1):
    for k in range(10*(i+1)+1):
      if j>=a and k>=b:
        DP[i+1][j][k]=min(DP[i][j-a][k-b]+c,DP[i][j][k])
      else:
        DP[i+1][j][k]=DP[i][j][k]
ans=inf
for i in range(1,10*n+1):
  if i*mb%ma==0:
    j=i*mb//ma
    ans=min(ans,DP[n][i][j])
print(ans if ans!=inf else -1)

# Fixed version:
n,ma,mb=map(int,input().split())
inf=10**4
A=[]
append=A.append
for i in range(n):
  a,b,c=map(int,input().split())
  append([a,b,c])
DP=[[[inf]*(10*n+1) for _ in range(10*n+1)] for _ in range(n+1)]
DP[0][0][0]=0
for i in range(n):
  a,b,c=A[i][0],A[i][1],A[i][2]
  for j in range(10*(i+1)+1):
    for k in range(10*(i+1)+1):
      if j>=a and k>=b:
        DP[i+1][j][k]=min(DP[i][j-a][k-b]+c,DP[i][j][k])
      else:
        DP[i+1][j][k]=DP[i][j][k]
ans=inf
for i in range(10*n+1):
  for j in range(10*n+1):
    if i*mb==j*ma and i*j!=0:
      ans=min(ans,DP[n][i][j])
print(ans if ans!=inf else -1)

# Buggy version:
N,A,B = list(map(int,input().split()))

item=[]
for i in range(N):
    a,b,c = list(map(int,input().split()))
    item.append([a,b,c])

D = [[10**27 for i in range(401)] for j in range(401)]
D[0][0] = 0
for i in range(N):
    for j in range(401):
        for k in range(401):
            if D[j][k]<10**27:
                D[j+item[i][0]][k+item[i][1]] = min(D[j+item[i][0]][k+item[i][1]],D[j][k]+item[i][2])

i=1
min_cost=10**27
while A*i<=400 and B*i<=400:
    min_cost = min(D[A*i][B*i],min_cost)
    i+=1
if min_cost==10**27:
	print(-1)
else:
	print(min_cost)

# Fixed version:

N,A,B = list(map(int,input().split()))

item=[]
for i in range(N):
    a,b,c = list(map(int,input().split()))
    item.append([a,b,c])

D = [[[10**27 for i in range(401)] for j in range(401)] for k in range(N+1)]
D[0][0][0] = 0
for i in range(N):
    for j in range(401):
        for k in range(401):
            if D[i][j][k]<10**26:
                D[i+1][j][k]=min(D[i+1][j][k],D[i][j][k])
                D[i+1][j+item[i][0]][k+item[i][1]] = min(D[i+1][j+item[i][0]][k+item[i][1]],D[i][j][k]+item[i][2])

i=1
min_cost=10**27
while A*i<=400 and B*i<=400:
    min_cost = min(D[N][A*i][B*i],min_cost)
    i+=1
if min_cost==10**27:
	print(-1)
else:
	print(min_cost)

# Buggy version:
N, Ma, Mb = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(N)]

inf = float("inf")

dp = [ [ [inf] * 401 for _ in range(401)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  a,b,c = ABC[i]
  for ma in range(400):
    for mb in range(400):
      dp[i+1][ma][mb] = min(dp[i+1][ma][mb],
                            dp[i][ma][mb])
      if ma + a > 400: continue
      if mb + b > 400: continue
        
      dp[i+1][ma+a][mb+b] = \
      min(dp[i+1][ma+a][mb+b],
          dp[i][ma][mb]+c)
      
ans = inf
for i in range(1,40000):
  if Ma*i > 400 or Mb*i > 400: break
  ans = min(ans, dp[N][Ma*i][Mb*i])

print(ans)

# Fixed version:
N, Ma, Mb = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(N)]

inf = float("inf")

dp = [ [ [inf] * 401 for _ in range(401)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  a,b,c = ABC[i]
  for ma in range(400):
    for mb in range(400):
      dp[i+1][ma][mb] = min(dp[i+1][ma][mb],
                            dp[i][ma][mb])
      if ma + a > 400: continue
      if mb + b > 400: continue
        
      dp[i+1][ma+a][mb+b] = \
      min(dp[i+1][ma+a][mb+b],
          dp[i][ma][mb]+c)
      
ans = inf
for i in range(1,40000):
  if Ma*i > 400 or Mb*i > 400: break
  ans = min(ans, dp[N][Ma*i][Mb*i])

if ans == inf:
  print(-1); exit()
print(ans)

# Buggy version:
N,Ma,Mb=map(int,input().split())

A,B,C = [],[],[]
for i in range(N):
    a,b,c=map(int,input().split())
    A += [a]
    B += [b]
    C += [c]

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

dp[0][0][0]=0
for i in range(N):
    for ca in range(i * 10):
        for cb in range(i * 10):
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])
            dp[i+1][ca+A[i]][cb+B[i]] = min(dp[i+1][ca+A[i]][cb+B[i]],dp[i][ca][cb]+C[i])

ans = 10**18
for ca in range(401):
    for cb in range(401):
        if not ca*Mb == cb*Ma or ca == 0:
            continue
        if ans > dp[N][ca][cb]:
            ans = dp[N][ca][cb]
        
if ans == 10**18:
    print(-1)
else:
    print(ans)


# Fixed version:
N,Ma,Mb=map(int,input().split())

dp = [[10**18 for _ in range(401)] for _ in range(401)]

dp[0][0]=0
for i in range(N):
    a,b,c=map(int,input().split())
    for ca in range(i * 10, -1, -1):
        for cb in range(i * 10, -1, -1):
            dp[ca+a][cb+b] = min(dp[ca+a][cb+b],dp[ca][cb]+c)

ans = 10**18
for ca in range(401):
    for cb in range(401):
        if not ca*Mb == cb*Ma or ca == 0:
            continue
        if ans > dp[ca][cb]:
            ans = dp[ca][cb]
        
if ans == 10**18:
    print(-1)
else:
    print(ans)

# Buggy version:
from math import isinf

N, Ma, Mb = map(int, input().split())
a = [0]*N
b = [0]*N
c = [0]*N
for i in range(N):
    a[i],b[i],c[i] = map(int, input().split())

W_MAX = 40*10
dp = [[float('inf')]*(W_MAX+1) for _ in range(W_MAX+1)]
dp[0][0] = 0

for i in range(N):
    for wa in range(W_MAX):
        for wb in range(W_MAX):
            if isinf(dp[wa][wb]): continue
            if wa+a[i]<=W_MAX and wb+b[i]<=W_MAX:
                dp[wa+a[i]][wb+b[i]] = min(dp[wa+a[i]][wb+b[i]],
                                           dp[wa][wb]+c[i])
ans = float('inf')
for wa in range(1, W_MAX+1):
    for wb in range(1, W_MAX+1):
        if wa*Mb == wb*Ma:
            ans = min(ans, dp[wa][wb])
print(ans)

# Fixed version:
from math import isinf

N, Ma, Mb = map(int, input().split())
a = [0]*N
b = [0]*N
c = [0]*N
for i in range(N):
    a[i],b[i],c[i] = map(int, input().split())

W_MAX = 40*10
dp = [[float('inf')]*(W_MAX+1) for _ in range(W_MAX+1)]
dp[0][0] = 0

for i in range(N):
    for wa in reversed(range(W_MAX+1)):
        for wb in reversed(range(W_MAX+1)):
            if isinf(dp[wa][wb]): continue
            if wa+a[i]<=W_MAX and wb+b[i]<=W_MAX:
                dp[wa+a[i]][wb+b[i]] = min(dp[wa+a[i]][wb+b[i]],
                                           dp[wa][wb]+c[i])

ans = float('inf')
for wa in range(1, W_MAX+1):
    for wb in range(1, W_MAX+1):
        if wa*Mb == wb*Ma:
            ans = min(ans, dp[wa][wb])

if isinf(ans): ans = -1
print(ans)

# Buggy version:
n,Ma,Mb=map(int,input().split())
inf=float("inf")
dp=[[[inf]*401 for _ in range(401)] for _ in range(n+1)]
dp[0][0][0]=0

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

for i in range(1,n+1):
    for j in range(401):
        for k in range(401):
            a,b,c=l[i-1]
            dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k])
            if j-a>=0 and k-b>=0:
                dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a][k-b]+c)

ans=inf
for i in range(1,1+max(400//Ma,400//Mb)):
    ans=min(ans,dp[n][Ma*i][Mb*i])

print(ans if ans!=inf else -1)

# Fixed version:
n,Ma,Mb=map(int,input().split())
inf=float("inf")
dp=[[[inf]*401 for _ in range(401)] for _ in range(n+1)]
dp[0][0][0]=0

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

for i in range(1,n+1):
    for j in range(401):
        for k in range(401):
            a,b,c=l[i-1]
            dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k])
            if j-a>=0 and k-b>=0:
                dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a][k-b]+c)

ans=inf
for i in range(1,401):
    for j in range(1,401):
        if i*Mb==j*Ma:
            ans=min(ans,dp[n][i][j])

print(ans if ans!=inf else -1)

# Buggy version:
N, Ma, Mb = (list)(map(int, input().split()))
N_max = 40
abmax = 10
l = []
inf = 10**6
dp = [[[inf]*401 for _ in range(401)] for _ in range(40)]


for _ in range(N):
    l.append((list)(map(int, input().split())))

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

for i in range(N):
    for ca in range(401):
        for cb in range(401):
            if dp[i][ca][cb] != inf:
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
                t_a = l[i][0]
                t_b = l[i][1]
                dp[i+1][ca+t_a][cb+t_b] =\
                    min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])

ans = inf
for i in range(401):
    for j in range(401):
        if i*Mb == j*Ma:
            ans = min(ans, dp[N][i][j])

if ans == inf:
    ans = -1
print(ans)


# Fixed version:
N, Ma, Mb = (list)(map(int, input().split()))
l = []
inf = 10**6
dp = [[[inf]*401 for _ in range(401)] for _ in range(41)]


for _ in range(N):
    l.append((list)(map(int, input().split())))

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

for i in range(N):
    for ca in range(401):
        for cb in range(401):
            if dp[i][ca][cb] != inf:
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
                t_a = l[i][0]
                t_b = l[i][1]
                dp[i+1][ca+t_a][cb+t_b] =\
                    min(dp[i+1][ca+t_a][cb+t_b], dp[i][ca][cb]+l[i][2])

ans = inf
for i in range(1, 401):
    for j in range(1, 401):
        if i*Mb == j*Ma:
            ans = min(ans, dp[N][i][j])

if ans == inf:
    ans = -1
print(ans)

# Buggy version:
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

inf = float("inf")
dp = [[[inf for _ in range(401)] for _ in range(401)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for a in range(401):
        for b in range(401):
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + items[i][0]][b + items[i][1]] = min(dp[i + 1][a + items[i][0]][b + items[i][1]],
                                                              dp[i][a][b] + items[i][2])
ans = inf
for a in range(1, 401):
    for b in range(1, 401):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans != inf:
    print(ans)
else:
    print(-1)

# Fixed version:
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(401)] for _ in range(401)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for a in range(a_sum + 1):
        for b in range(b_sum + 1):
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + items[i][0]][b + items[i][1]] = min(dp[i + 1][a + items[i][0]][b + items[i][1]],
                                                              dp[i][a][b] + items[i][2])
ans = inf
for a in range(1, a_sum + 1):
    for b in range(1, b_sum + 1):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans != inf:
    print(ans)
else:
    print(-1)

# Buggy version:
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(b_sum + 11)] for _ in range(a_sum + 11)] for i in range(N + 1)]
dp[0][0][0] = 0
print(a_sum, b_sum)
for i in range(N):
    for a in range(a_sum):
        for b in range(b_sum):
            if dp[i + 1][a][b] > dp[i][a][b]:
                dp[i + 1][a][b] = dp[i][a][b]
            if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
                dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]

ans = inf
for a in range(1, a_sum + 1):
    for b in range(1, b_sum + 1):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans != inf:
    print(ans)
else:
    print(-1)


# Fixed version:
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(a_sum + 100)] for _ in range(b_sum + 100)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for a in range(a_sum + 1):
        for b in range(b_sum + 1):
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + items[i][0]][b + items[i][1]] = min(dp[i + 1][a + items[i][0]][b + items[i][1]],
                                                              dp[i][a][b] + items[i][2])
ans = inf
for a in range(1, a_sum + 1):
    for b in range(1, b_sum + 1):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans != inf:
    print(ans)
else:
    print(-1)

# Buggy version:
N,Ma,Mb=list(map(int,input().split()))

mix=set([(0,0)])
ans=10**9
cost={(0,0):0}
for i in range(N):
    a,b,c=list(map(int,input().split()))
    tmp=mix.copy()
    for x in tmp:
        d=x[0]+a
        e=x[1]+b
        f=min(cost.get((d,e),10**9),cost[x]+c)
        cost[(d,e)]=f
        mix.add((d, e))
        if d*Mb==e*Ma and f<ans:
            ans=f
print(cost)
print(mix)
if ans==10**9:
    ans=-1
print(ans)

# Fixed version:
N,Ma,Mb=list(map(int,input().split()))

mix=set([(0,0)])
ans=10**9
cost={(0,0):0}
for i in range(N):
    a,b,c=list(map(int,input().split()))
    tmp=mix.copy()
    tmp2=cost.copy()
    for x in tmp:
        d=x[0]+a
        e=x[1]+b
        f=min(tmp2.get((d,e),10**9),tmp2[x]+c)
        cost[(d,e)]=f
        mix.add((d, e))
        if d*Mb==e*Ma and f<ans:
            ans=f
"""
print(cost)
print(mix)
"""
if ans==10**9:
    ans=-1
print(ans)

# Buggy version:
global N
global Nlist
global Ma
global Mb
global minicost
minicost = 10000000
N, Ma, Mb = map(int,input().split()) 
Nlist = []
for i in range(N):
    a,b,c = map(int,input().split())
    Nlist.append([a,b,c])
def dvector(Masum,Mbsum,cost,vector):
    print(vector)
    global Ma
    global Mb
    global Nlist
    global minicost
    if len(vector) == len(Nlist):
        return 0
    dvector(Masum,Mbsum,cost,vector+[0])
    Masum+= Nlist[len(vector)-1][0]
    Mbsum+= Nlist[len(vector)-1][1]
    cost += Nlist[len(vector)-1][2]
    if Mbsum > 0:
        if Masum/Mbsum == Ma/Mb:
            if minicost > cost:
                minicost = cost
    print(vector,cost,minicost)
    if cost < minicost:
        dvector(Masum,Mbsum,cost,vector+[1])
    return 0
    
dvector(0,0,0,[])
if minicost == 10000000:
    print("-1")
else:
    print(minicost)

# Fixed version:
global N
global Nlist
global Ma
global Mb
global minicost
minicost = 10000000
N, Ma, Mb = map(int,input().split()) 
Nlist = []
for i in range(N):
    a,b,c = map(int,input().split())
    Nlist.append([a,b,c])

def dvector(Masum,Mbsum,cost,vector):
    global Ma
    global Mb
    global Nlist
    global minicost
    if len(vector) == len(Nlist):
        return 0
    dvector(Masum,Mbsum,cost,vector+[0])
    Masum+= Nlist[len(vector)-1][0]
    Mbsum+= Nlist[len(vector)-1][1]
    cost += Nlist[len(vector)-1][2]
    if Mbsum > 0:
        if Masum/Mbsum == Ma/Mb:
            if minicost > cost:
                minicost = cost
    if cost < minicost:
        dvector(Masum,Mbsum,cost,vector+[1])
    return 0
    
dvector(0,0,0,[])
if minicost == 10000000:
    print("-1")
else:
    print(minicost)

# Buggy version:
import copy

N, Ma, Mb = [int(n) for n in input().split()]
pd = {(0,0):0}
for i in range(N):
    a, b, c = [int(n) for n in input().split()]
    pdcopy = copy.deepcopy(pd)
    for k, v in pdcopy.items():
        nk = (k[0]+a, k[1]+b)
        if nk in pd:
            if pd[nk] > c :
                pd[nk] = c
        else:
            pd[nk] = c

mp = 1000000
for i in range(1,401):
    if (Ma*i, Mb*i) in pd:
        mp = min(pd[(Ma*i, Mb*i)], mp)

if mp == 1000000:
    print(-1)
else:
    print(mp)


# Fixed version:
import copy

N, Ma, Mb = [int(n) for n in input().split()]
pd = {(0,0):0}
for i in range(N):
    a, b, c = [int(n) for n in input().split()]
    pdcopy = copy.deepcopy(pd)
    for k, v in pdcopy.items():
        nk = (k[0]+a, k[1]+b)
        if nk in pd:
            if pd[nk] > v + c :
                pd[nk] = v + c
        else:
            pd[nk] = v + c

mp = 1000000
for i in range(1,401):
    if (Ma*i, Mb*i) in pd:
        mp = min(pd[(Ma*i, Mb*i)], mp)

if mp == 1000000:
    print(-1)
else:
    print(mp)