CodeEff/ECCO huggingface dataset:
# Original solution
global N
global Nlist
global Ma
global Mb
global minicost
minicost = 10000000
N, Ma, Mb = list(map(int,input().split())) 
Nlist = []
for i in range(N):
    a,b,c = list(map(int,input().split()))
    Nlist.append([a,b,c])

def dvector(vector):
    global Ma
    global Mb
    global Nlist
    global minicost
    if len(vector) == len(Nlist):
        return 0
    vector.append(1)
    Masum = 0
    Mbsum = 0
    cost = 0
    for i in range(len(vector)):
        Masum+= vector[i] * Nlist[i][0]
        Mbsum+= vector[i] * Nlist[i][1]
        cost += vector[i] * Nlist[i][2]
        if Mbsum > 0:
            if Masum/Mbsum == Ma/Mb:
                if minicost > cost:
                    minicost = cost
        if cost < minicost:
            dvector(vector)
    vector.pop()
    vector.append(0)
    dvector(vector)
    vector.pop()
    return 0
    
dvector([])
if minicost == 10000000:
    print("-1")
else:
    print(minicost)

# Optimized solution
global N
global Nlist
global Ma
global Mb
global minicost
minicost = 10000000
N, Ma, Mb = list(map(int,input().split())) 
Nlist = []
for i in range(N):
    a,b,c = list(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)
# Original solution
n,Ma,Mb=list(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))

# Optimized solution
n,Ma,Mb=list(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+min(400//Ma,400//Mb)):
    ans=min(ans,dp[n][Ma*i][Mb*i])

print((ans if ans!=inf else -1))
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**5
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    n,ma,mb = LI()
    med = [LI() for _ in range(n)]
    h1 = []
    h2 = []

    for i in range(2 ** (n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n//2):
            if i & bit:
                a,b,c = med[j]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = ta * mb - tb * ma
        h1.append((dif,tc))

    for i in range(2 ** (n - n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n - n//2):
            if i & bit:
                a,b,c = med[j+n//2]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = tb * ma - ta * mb
        h2.append((dif,tc))

    h1.sort()
    h2.sort()
    i = 0
    ans = INF
    for h,c in h1:
        while h2[i][0] < h:
            i += 1
            if i >= len(h2): break
        else:
            k = i
            while h2[k][0] == h:
                if c != 0 or h2[k][1] != 0:
                    ans = min(ans,c+h2[k][1])
                k += 1
                if k >= len(h2): break

        if i >= len(h2): break
    if ans < INF:
        print(ans)
    else:
        print((-1))

if __name__ == '__main__':
    main()

# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**5
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    n,ma,mb = LI()
    med = [LI() for _ in range(n)]
    h1 = [INF] * 10000

    for i in range(1,2 ** (n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n//2):
            if i & bit:
                a,b,c = med[j]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = ta * mb - tb * ma
        if h1[dif] > tc: h1[dif] = tc

    ans = h1[0]

    for i in range(1,2 ** (n - n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n - n//2):
            if i & bit:
                a,b,c = med[j+n//2]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = tb * ma - ta * mb
        if dif == 0:
            ans = min(ans,tc)
        else:
            ans = min(ans,h1[dif]+tc)

    if ans < INF:
        print(ans)
    else:
        print((-1))

if __name__ == '__main__':
    main()
# Original solution
n,ma,mb = (int(i) for i in input().split())
dp = [[[float("inf") for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,float("inf")
for i in range(1,n+1):
	x,y,c = (int(l) for l in input().split())
	for j in range(10*(i-1)+1):
		for k in range(10*(i-1)+1):
			if dp[i-1][j][k]!=float("inf"):
				dp[i][j][k] = min(dp[i-1][j][k],dp[i][j][k])
				dp[i][j+x][k+y] = min(dp[i][j+x][k+y],dp[i-1][j][k]+c)
for i in range(ma,10*n+1,ma):
	if i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])
if ans==float("inf"): print((-1))
else: print(ans)

# Optimized solution
n, ma, mb = list(map(int, input().split()))
INF = float("inf")
dp = [[[INF for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,INF
for i in range(1,n+1):
    a,b,c = (int(l) for l in input().split())
    for j in range(10*(i-1)+1):
        for k in range(10*(i-1)+1):
            if dp[i-1][j][k] != INF:
              dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k])
              dp[i][j+a][k+b] = min(dp[i][j+a][k+b], dp[i-1][j][k]+c)
for i in range(ma,10*n+1,ma):
	if i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])
if ans==INF: print((-1))
else: print(ans)
# Original solution
import fractions

n, ma, mb = list(map(int,input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int,input().split()))

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[float('inf') for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

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

for i in range(1, n + 1):
    for j in range(401):
        for k in range(401):
            # i番目を買うか、買わないか
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = float('inf')
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == float('inf'):
    ans = -1

print(ans)

# Optimized solution
import fractions

n, ma, mb = list(map(int,input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int,input().split()))

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10**15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]

for i in range(1, n + 1):
    for j in range(401):
        if j > sa[i]:
            break
        for k in range(401):
            if k > sb[i]:
                break
            # i番目を買うか、買わないか
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)
# Original solution
import fractions

n, ma, mb = list(map(int,input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int,input().split()))

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    for j in range(401):
        for k in range(401):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)

"""
import fractions

n, ma, mb = map(int,input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = map(int,input().split())

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]

for i in range(1, n + 1):
    for j in range(sa[i] + 1):
        for k in range(sb[i] + 1):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)
"""


# Optimized solution
n, ma, mb = list(map(int,input().split()))
a = [0] * (n + 1)
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(1, n + 1):
    a[i], b[i], c[i] = list(map(int,input().split()))

#iまでの薬品で、aがj(g),bがk(g)となるときの最小コスト
dp = [[[10 ** 15 for i in range(n + 1)] for j in range(401)] \
    for k in range(401)]

dp[0][0][0] = 0
sa = [0] * (n + 1)
sb = [0] * (n + 1)

for i in range(1, n + 1):
    sa[i] = sa[i - 1] + a[i]
    sb[i] = sb[i - 1] + b[i]

for i in range(1, n + 1):
    for j in range(sa[i] + 1):
        for k in range(sb[i] + 1):
            if j < a[i] or k < b[i]:
                dp[k][j][i] = dp[k][j][i - 1]
            else:
                dp[k][j][i] = min(dp[k][j][i - 1], \
                    dp[k - b[i]][j - a[i]][i - 1] + c[i])

i = 1
ans = 10 ** 15
while True:
    if i * ma > 400 or i * mb > 400:
        break
    ans = min(ans, dp[i * mb][i * ma][n])
    i += 1

if ans == 10 ** 15:
    ans = -1

print(ans)
# Original solution
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


n, ma, mb = LI()
abc = [tuple(LI()) for _ in range(n)]
ab_max = n * 10 + 1

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


for i in range(n):
    ai, bi, ci = abc[i]
    for a in range(ab_max - ai):
        for b in range(ab_max - bi):
            if dp[i][a][b] == INF:
                continue
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)


ans = INF
c = 1
while True:
    a, b = c * ma, c * mb
    if a >= ab_max or b >= ab_max:
        break
    ans = min(ans, dp[n][a][b])
    c += 1

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


# Optimized solution
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())


n, ma, mb = LI()
src = []
a_max, b_max = 1, 1
for _ in range(n):
    a, b, c = LI()
    src.append((a, b, c))
    a_max += a
    b_max += b

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


for i in range(n):
    ai, bi, ci = src[i]
    for a in range(a_max - ai):
        for b in range(b_max - bi):
            if dp[i][a][b] == INF:
                continue
            dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])
            dp[i + 1][a + ai][b + bi] = min(dp[i][a + ai][b + bi], dp[i][a][b] + ci)


ans = INF
c = 1
while True:
    a, b = c * ma, c * mb
    if a >= a_max or b >= b_max:
        break
    ans = min(ans, dp[n][a][b])
    c += 1

print((ans if ans != INF else -1))
# Original solution
N,Ma,Mb = list(map(int,input().split()))

INF = 10000

dp = [[[INF for b in range(401)] for a in range(401)] for i in range(N+1)]

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

for i in range(1,N+1):
    ai,bi,ci = list(map(int,input().split()))
    for a in range(401):
        for b in range(401):
            if a-ai >= 0 and b-bi >= 0:
                dp[i][a][b] = min(dp[i-1][a][b],dp[i-1][a-ai][b-bi]+ci)
            else:
                dp[i][a][b] = dp[i-1][a][b]

ans = INF
for j in range(1,401):
    if Ma*j >= 400 or Mb*j >= 400:
        break
    ans = min(ans,dp[N][Ma*j][Mb*j])
print((ans if ans != INF else -1))



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

INF = 10000

dp = [[INF for b in range(401)] for a in range(401)]

dp[0][0] = 0

for i in range(1,N+1):
    ai,bi,ci = list(map(int,input().split()))
    for a in range(400,-1,-1):
        for b in range(400,-1,-1):
            if a-ai >= 0 and b-bi >= 0:
                dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci)


ans = INF
for j in range(1,401):
    if Ma*j > 400 or Mb*j > 400:
        break
    ans = min(ans,dp[Ma*j][Mb*j])
print((ans if ans != INF else -1))
# Original solution
N,Ma,Mb = list(map(int,input().split()))

INF = float('inf')

dp = [[INF for b in range(401)] for a in range(401)]

dp[0][0] = 0

for i in range(1,N+1):
    ai,bi,ci = list(map(int,input().split()))
    for a in range(400,-1,-1):
        for b in range(400,-1,-1):
            if a-ai >= 0 and b-bi >= 0:
                dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci)


ans = INF
for j in range(1,401):
    if Ma*j > 400 or Mb*j > 400:
        break
    ans = min(ans,dp[Ma*j][Mb*j])
print((ans if ans != INF else -1))


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

INF = float('inf')

dp = [[INF for b in range(401)] for a in range(401)]

dp[0][0] = 0

sa = 0
sb = 0

for i in range(1,N+1):
    ai,bi,ci = list(map(int,input().split()))
    sa += ai
    sb += bi
    for a in range(sa+1,-1,-1):
        for b in range(sb+1,-1,-1):
            if a-ai >= 0 and b-bi >= 0:
                dp[a][b] = min(dp[a][b],dp[a-ai][b-bi]+ci)


ans = INF
for j in range(1,401):
    if Ma*j > 400 or Mb*j > 400:
        break
    ans = min(ans,dp[Ma*j][Mb*j])
print((ans if ans != INF else -1))
# Original solution
N,MA,MB = list(map(int,input().split()))
src = []
sum_a = sum_b = 0
for i in range(N):
  a,b,c = list(map(int,input().split()))
  src.append((a,b,c))
  sum_a += a
  sum_b += b

INF = 10**9
dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  ai,bi,ci = src[i]
  for a in range(sum_a+1 - ai):
    for b in range(sum_b+1 - bi):
      dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)

ans = INF
n = 1
while True:
  a,b = n*MA,n*MB
  if a > sum_a or b > sum_b: break
  ans = min(ans, dp[N][a][b])
  n += 1

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

# Optimized solution
N,MA,MB = list(map(int,input().split()))
src = []
sum_a = sum_b = 0
for i in range(N):
  a,b,c = list(map(int,input().split()))
  src.append((a,b,c))
  sum_a += a
  sum_b += b

INF = 10**9
dp = [[[INF for b in range(sum_b+1)] for a in range(sum_a+1)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  ai,bi,ci = src[i]
  for a in range(sum_a+1 - ai):
    for b in range(sum_b+1 - bi):
      if dp[i][a][b] == INF: continue
      dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
      dp[i+1][a+ai][b+bi] = min(dp[i][a+ai][b+bi], dp[i][a][b] + ci)

ans = INF
n = 1
while True:
  a,b = n*MA,n*MB
  if a > sum_a or b > sum_b: break
  ans = min(ans, dp[N][a][b])
  n += 1

print((ans if ans != INF else -1))
# Original solution
N,MA,MB = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(N)]

INF = 10**9
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0
maxa = maxb = 0
for a,b,c in src:
    for ai in range(maxa,-1,-1):
        for bi in range(maxb,-1,-1):
            dp[ai+a][bi+b] = min(dp[ai+a][bi+b], dp[ai][bi] + c)
    maxa += a
    maxb += b

ans = INF
for i in range(1,401):
    if MA*i > 400 or MB*i > 400: break
    ans = min(ans, dp[MA*i][MB*i])
print((-1 if ans == INF else ans))

# Optimized solution
N,MA,MB = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(N)]

INF = 10**9
MAX = 401
dp = [[INF] * MAX for i in range(MAX)]
dp[0][0] = 0
amax = bmax = 0
for a,b,n in src:
    for i in reversed(list(range(bmax+1))):
        for j in range(amax+1):
            if dp[i][j] == INF: continue
            dp[i+b][j+a] = min(dp[i+b][j+a], dp[i][j] + n)
    amax += a
    bmax += b

ans = INF
for i in range(1,MAX):
    if i*MA >= MAX or i*MB >= MAX: break
    ans = min(ans, dp[i*MB][i*MA])
print((-1 if ans == INF else ans))
# Original solution
N , Ma, Mb = list(map(int, input().split()))

a = [0] * N
b = [0] * N
c = [0] * N

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

# 最小値を求める問題なのでinfで初期化
# dp[i][sun_a][sum_b]で考えていく
dp = [[[float('inf') for _ in range(10 * N + 1)] for _ in range(10 * N + 1)] for _ in range(N+1)]

# 初期選択状態を0とする

dp[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if dp[i][j][k] == float('inf'):
                continue
            
            # 選ばなかった場合
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            # 選んだ場合
            dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i])


ans = float('inf')
# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する

# TLEになったため変更
#for i in range(1,10 * N + 1):
#    for j in range(1,10 * N + 1):
#        if i * Mb != j * Ma:
#            continue
#        ans = min(ans, dp[N][i][j])
#

for i in range(1, 10*N+1):
        if i*Ma>10*N or i*Mb>10*N:
            break
        ans = min(ans, dp[N][i*Ma][i*Mb])

if ans == float('inf'):
    print((-1))
else:
    print(ans)

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

a = [0] * N
b = [0] * N
c = [0] * N

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

# TLEになってしまうためinfを5000とかで設定する
INF = 5000

# 最小値を求める問題なのでinfで初期化
# dp[i][sun_a][sum_b]で考えていく
dp = [[[INF for _ in range(10 * N + 1)] for _ in range(10 * N + 1)] for _ in range(N+1)]

# 初期選択状態を0とする

dp[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if dp[i][j][k] == INF:
                continue
            
            # 選ばなかった場合
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            # 選んだ場合
            dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i])


ans = INF
# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する

# TLEになったため変更
#for i in range(1,10 * N + 1):
#    for j in range(1,10 * N + 1):
#        if i * Mb != j * Ma:
#            continue
#        ans = min(ans, dp[N][i][j])
#

for i in range(1, 10*N+1):
        if i*Ma>10*N or i*Mb>10*N:
            break
        ans = min(ans, dp[N][i*Ma][i*Mb])

if ans == INF:
    print((-1))
else:
    print(ans)
# Original solution
N , Ma, Mb = list(map(int, input().split()))

a = [0] * N
b = [0] * N
c = [0] * N

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

# TLEになってしまうためinfを5000とかで設定する
INF = 5000
# さらに計算量を落とすため10 * N + 1などを定数で設定する

# 最小値を求める問題なのでinfで初期化
# dp[i][sun_a][sum_b]で考えていく
dp = [[[INF for _ in range(401)] for _ in range(401)] for _ in range(41)]

# 初期選択状態を0とする

dp[0][0][0] = 0
for i in range(N):
    for j in range(401):
        for k in range(401):
            if dp[i][j][k] == INF:
                continue
            
            # 選ばなかった場合
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            # 選んだ場合
            dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i])


ans = INF
# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する

# TLEになったため変更
#for i in range(1,10 * N + 1):
#    for j in range(1,10 * N + 1):
#        if i * Mb != j * Ma:
#            continue
#        ans = min(ans, dp[N][i][j])
#

for i in range(1, 401):
        if i*Ma>10*N or i*Mb>10*N:
            break
        ans = min(ans, dp[N][i*Ma][i*Mb])

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

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

# 入力値の受け取り方を変える

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

#a = [0] * N
#b = [0] * N
#c = [0] * N

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



# TLEになってしまうためinfを5000とかで設定する
INF = 5000
# さらに計算量を落とすため10 * N + 1などを定数で設定する →　関係なかったため戻す

# 最小値を求める問題なのでinfで初期化
# dp[i][sun_a][sum_b]で考えていく
dp = [[[INF for _ in range(10 * N + 1)] for _ in range(10 * N + 1)] for _ in range(N+1)]

# 初期選択状態を0とする

dp[0][0][0] = 0
for i in range(N):
    a,b,c=arr[i]
    for j in range(10*N+1):
        for k in range(10*N+1):
            if dp[i][j][k] == INF:
                continue
            
            # 選ばなかった場合
            dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
            # 選んだ場合
            dp[i+1][j+a][k+b] = min(dp[i+1][j+a][k+b], dp[i][j][k] + c)


ans = INF
# 0スタートは何を選んでいない状態となり最小値が0になってしまうため1から開始する

# TLEになったため変更
#for i in range(1,10 * N + 1):
#    for j in range(1,10 * N + 1):
#        if i * Mb != j * Ma:
#            continue
#        ans = min(ans, dp[N][i][j])
#

for i in range(1, 10*N+1):
        if i*Ma>10*N or i*Mb>10*N:
            break
        ans = min(ans, dp[N][i*Ma][i*Mb])

if ans == INF:
    print((-1))
else:
    print(ans)
# Original solution
N,Ma,Mb = list(map(int, input().split()))
arr=[list(map(int,input().split())) for _ in range(N)]
dp=[[[5000]*401 for _ in range(401)] for _ in range(41)]
dp[0][0][0] = 0
for i in range(N):
    a,b,c=arr[i]
    for j in range(10*N+1):
        for k in range(10*N+1):
            if dp[i][j][k] == 5000:
                continue
            dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
            dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)

ans=5000
for i in range(1,401):
        if i*Ma>400 or i*Mb>400:
            break
        ans = min(ans, dp[N][i*Ma][i*Mb])
if ans == 5000:
    print((-1))
else:
    print(ans)

# Optimized solution
def calc():
    N,Ma,Mb = list(map(int, input().split()))
    arr=[list(map(int,input().split())) for _ in range(N)]
    dp=[[[5000]*401 for _ in range(401)] for _ in range(41)]
    dp[0][0][0] = 0
    for i in range(N):
        a,b,c=arr[i]
        for j in range(10*N+1):
            for k in range(10*N+1):
                if dp[i][j][k] == 5000:
                    continue
                dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
                dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)

    ans=5000
    for i in range(1,401):
            if i*Ma>400 or i*Mb>400:
                break
            ans = min(ans, dp[N][i*Ma][i*Mb])
    if ans == 5000:
        print((-1))
    else:
        print(ans)

calc()