CodeEff/ECCO huggingface dataset:
# Original solution
def sol():
    N, Ma, Mb = list(map(int, input().split()))
    items = []
    for _ in range(N):
        a, b, c = list(map(int, input().split()))
        items.append((a, b, c))

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

    for i, (a, _, _) in enumerate(items):
        for mod in range(Ma):
            for prev in dp[i][mod]:
                dp[i + 1][mod].append(prev)
            for prev in dp[i][(mod - a) % Ma]:
                dp[i + 1][mod].append(prev + [i])

    maList = [A for A in dp[N][0] if len(A) > 0]

    ans = float('inf')
    for addList in maList:
        sumA = 0
        sumB = 0
        cost = 0
        for i in addList:
            sumA += items[i][0]
            sumB += items[i][1]
            cost += items[i][2]
        if sumA * Mb == sumB * Ma:
            ans = min(ans, cost)

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

sol()

# Optimized solution
def sol():
    N, Ma, Mb = list(map(int, input().split()))
    items = []
    for _ in range(N):
        a, b, c = list(map(int, input().split()))
        items.append((a, b, c))

    dp = [[set([()]) for _ in range(Ma)] for _ in range(N + 1)]

    for i, (a, _, _) in enumerate(items):
        for mod in range(Ma):
            for prev in dp[i][mod]:
                dp[i + 1][mod].add(prev)
            for prev in dp[i][(mod - a) % Ma]:
                dp[i + 1][mod].add(tuple(list(prev) + [i]))

    maList = [A for A in dp[N][0] if len(A) > 0]

    ans = float('inf')
    for addList in maList:
        sumA = 0
        sumB = 0
        cost = 0
        for i in addList:
            sumA += items[i][0]
            sumB += items[i][1]
            cost += items[i][2]
        if sumA * Mb == sumB * Ma:
            ans = min(ans, cost)

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

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

inf = float("inf")
dp = [[[inf for _ in range(411)] for _ in range(411)] 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))

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


# Optimized solution
N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
    a, b, c = list(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 + 60)] for _ in range(b_sum + 60)] for i in range(N + 1)]
dp[0][0][0] = 0

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))
# Original solution
N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
    a, b, c = list(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 + 50)] for _ in range(b_sum + 50)] for i in range(N + 1)]
dp[0][0][0] = 0

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))


# Optimized solution
N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
    a, b, c = list(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
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))
# Original solution
N, Ma, Mb = list(map(int, input().split()))
items = []
ap = items.append
a_sum =0
b_sum = 0
for i in range(N):
    a, b, c = list(map(int, input().split()))
    ap((a, b, c))
    a_sum += a
    b_sum += b

inf = float("inf")
dp = [[[inf for _ in range(b_sum + 10)] for _ in range(a_sum + 10)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    for a in range(a_sum):
        for b in range(b_sum):
            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))


# Optimized solution
N, Ma, Mb = list(map(int, input().split()))
items = []
ap = items.append
a_sum =0
b_sum = 0
for i in range(N):
    a, b, c = list(map(int, input().split()))
    ap((a, b, c))
    a_sum += a
    b_sum += b

inf = float("inf")
dp = [[[inf for _ in range(b_sum + 10)] for _ in range(a_sum + 10)] for i in range(N + 1)]
dp[0][0][0] = 0
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))
# Original solution
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()

# Optimized solution
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()
# Original solution
from copy import deepcopy
N, Ma, Mb = list(map(int, input().split()))
L = [[float("inf")]*410 for i in range(410)]
P = [[0, 0]]
L[0][0] = 0

for i in range(N):
    a, b, c = list(map(int, input().split()))
    OldP = P.copy()
    OldL = deepcopy(L)
    for p in OldP:
        if L[p[0]+a][p[1]+b] == float("inf"):
            P.append([p[0]+a, p[1]+b])
        L[p[0]+a][p[1]+b] = min(OldL[p[0]+a][p[1]+b], OldL[p[0]][p[1]]+c)
g = [Ma, Mb]
ans = float("inf")
while g[0]<410 and g[1]<410:
    ans = min(ans, L[g[0]][g[1]])
    g[0] += Ma
    g[1] += Mb
print((ans if ans != float("inf") else -1))


# Optimized solution
N, Ma, Mb = list(map(int, input().split()))
L = [[float("inf")]*410 for i in range(410)]
P = [[0, 0]]
L[0][0] = 0

for i in range(N):
    a, b, c = list(map(int, input().split()))
    OldP = P.copy()
    Lsub = [L[p[0]][p[1]] for p in OldP]
    for xp, p in enumerate(OldP):
        if L[p[0]+a][p[1]+b] == float("inf"):
            P.append([p[0]+a, p[1]+b])
        L[p[0]+a][p[1]+b] = min(L[p[0]+a][p[1]+b], Lsub[xp]+c)
g = [Ma, Mb]
ans = float("inf")
while g[0]<410 and g[1]<410:
    ans = min(ans, L[g[0]][g[1]])
    g[0] += Ma
    g[1] += Mb
print((ans if ans != float("inf") else -1))
# Original solution
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,Ma,Mb = list(map(int,input().split()))
    abc = [list(map(int,input().split())) for i in range(N)]

    INF = N * 100 + 1

    dp = [[[INF for cb in range(411)] for ca in range(411)] for i in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for ca in range(N*10):
            for cb in range(N*10):
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])
                d = abc[i]
                dp[i+1][ca+d[0]][cb+d[1]] = min(dp[i+1][ca+d[0]][cb+d[1]],dp[i][ca][cb]+d[2])

    res = INF

    for ca in range(1,401):
        for cb in range(1,401):
            if ca * Mb == cb * Ma:
                res = min(res,dp[N][ca][cb])

    if res == INF:
        res = -1

    print(res)



main()


# Optimized solution
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,Ma,Mb = list(map(int,input().split()))
    abc = [list(map(int,input().split())) for i in range(N)]

    INF = N * 100 + 1

    dp = [[[INF for cb in range(411)] for ca in range(411)] for i in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for ca in range(N*10):
            for cb in range(N*10):
                if dp[i][ca][cb] == INF:
                    continue
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb],dp[i][ca][cb])
                d = abc[i]
                dp[i+1][ca+d[0]][cb+d[1]] = min(dp[i+1][ca+d[0]][cb+d[1]],dp[i][ca][cb]+d[2])

    res = INF

    for ca in range(1,401):
        for cb in range(1,401):
            if ca * Mb == cb * Ma:
                res = min(res,dp[N][ca][cb])

    if res == INF:
        res = -1

    print(res)



main()
# Original solution
n,ma,mb = list(map(int, input().split()))
abcl = []
for _ in range(n):
    a,b,c = list(map(int, input().split()))
    abcl.append((a,b,c))

dp = [ [ [10**9]*401  for _ in range(401) ] for _ in range(n+1) ]
dp[0][0][0] = 0
for i in range(n):
    ai,bi,ci = abcl[i]
    for a in range(401):
        for b in range(401):
            if a+ai < 401 and b+bi < 401:
                dp[i+1][a][b] = min(dp[i][a][b], dp[i+1][a][b])
                dp[i+1][a+ai][b+bi] = min(dp[i][a][b] + ci, dp[i+1][a+ai][b+bi])


ans = 10**9
dp_row = dp[n]
for a in range(1,401):
    for b in range(1,401):
        if ma*b == mb*a:
            v = dp[n][a][b]
            ans = min(ans,v)

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

# Optimized solution
n,ma,mb = list(map(int, input().split()))
abcl = []
for _ in range(n):
    a,b,c = list(map(int, input().split()))
    abcl.append((a,b,c))

dp = [ [ [10**9]*401  for _ in range(401) ] for _ in range(n+1) ]
dp[0][0][0] = 0
for i in range(n):
    ai,bi,ci = abcl[i]
    for a in range(401):
        for b in range(401):
            dp[i+1][a][b] = min(dp[i][a][b], dp[i+1][a][b])
            if a+ai < 401 and b+bi < 401:
                dp[i+1][a+ai][b+bi] = min(dp[i][a][b] + ci, dp[i+1][a+ai][b+bi])


ans = 10**9
dp_row = dp[n]
for a in range(1,401):
    for b in range(1,401):
        if ma*b == mb*a:
            v = dp[n][a][b]
            ans = min(ans,v)

if ans == 10**9: ans = -1
print(ans)
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, a_ratio, b_ratio = LI()
L = LIR(n)
A, B, cost = [[L[i][j] for i in range(n)] for j in range(3)]
dp = [[INF] * 401 for _ in range(401)]
dp[0][0] = 0
for i in range(n):
    for j in range(401, -1, -1):
        for k in range(401, -1, -1):
            if 0 <= j + A[i] <= 400 and 0 <= k + B[i] <= 400:
                dp[j + A[i]][k + B[i]] = min(dp[j + A[i]][k + B[i]], dp[j][k] + cost[i])



ans = INF
for l in range(1, min(400 // b_ratio, 400 // a_ratio)):
    ans = min(ans, dp[a_ratio * l][b_ratio * l])


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


# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def gcd(i, j):
    while j:
        i, j = j, i % j
    return i


n, a_ratio, b_ratio = LI()
solution = LIR(n)
dp = {(0, 0): 0}
for a, b, c in solution:
    for (ai, bi), ci in list(dp.items()):
        # listにしないとduring iteration dictionary changeみたいなerrorでる。
        # メモ：defaultdictはもともと存在しないkeyを参照するだけでkey:valueが追加される。
        # これによって、key: INFが追加されるのはまずい。だからgetで
        dp[(ai + a, bi + b)] = min(dp.get((ai + a, bi + b), INF), ci + c)


ans = INF
for i in range(1, max(400 // a_ratio, 400 // b_ratio)):
    ans = min(ans, dp.get((a_ratio * i, b_ratio * i), INF))

print((ans if ans != INF else -1))
# Original solution
N, Ma, Mb = list(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)


# Optimized solution
N, Ma, Mb = list(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):
            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])
            else:
                dp[i + 1][j][k] = dp[i][j][k]
ans = inf
for a in range(1, 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)
# Original solution
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return list(map(list, list(zip(*read_all))))

#################

# Ma:Mbを満たす量を全探索する
# 量を決めたときの最小予算は半分全列挙から分かる

from itertools import product

N,Ma,Mb = LI()
a,b,c = LIR(N,3)

Z1 = list(product([0,1],repeat=N//2))
Z2 = list(product([0,1],repeat=N-N//2))

d1 = defaultdict(list)
d2 = defaultdict(list)

for z in Z1:
    val_a = 0
    val_b = 0
    cost = 0
    for i,z0 in enumerate(z):
        if z0:
            val_a += a[i]
            val_b += b[i]
            cost += c[i]
    d1[(val_a,val_b)].append(cost)

for k in list(d1.keys()):
    d1[k].sort()

for z in Z2:
    val_a = 0
    val_b = 0
    cost = 0
    for i,z0 in enumerate(z):
        if z0:
            val_a += a[N//2+i]
            val_b += b[N//2+i]
            cost += c[N//2+i]
    d2[(val_a,val_b)].append(cost)

for k in list(d2.keys()):
    d2[k].sort()

vals = []
now = 1
while True:
    if Ma*now <= sum(a) and Mb*now <= sum(b):
        vals.append((Ma*now,Mb*now))
        now += 1
    else:
        break

ans = float('inf')
for v in vals:
    for k in list(d1.keys()):
        left_a = v[0]-k[0]
        left_b = v[1]-k[1]
        if d2[(left_a,left_b)]:
            if d1[k][0]+d2[(left_a,left_b)][0] < ans:
                ans = d1[k][0]+d2[(left_a,left_b)][0]

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

# Optimized solution
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return list(map(list, list(zip(*read_all))))

#################

N,Ma,Mb = LI()
a,b,c = LIR(N,3)

amax = sum(a)
bmax = sum(b)

# dp[i][j][k]: 薬品iまで見て，Aがjグラム，Bがkグラムの最小予算
dp = [[[5000]*(bmax+1) for _ in range(amax+1)] for _ in range(N)]
dp[0][a[0]][b[0]] = c[0]
dp[0][0][0] = 0
for i in range(1,N):
    for j in range(amax+1):
        for k in range(bmax+1):
            if j == k == 0:
                dp[i][j][k] = 0
            elif j-a[i] < 0 or k-b[i] < 0:
                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[i]][k-b[i]]+c[i])

ans = 5000
now = 1
while True:
    if Ma*now <= amax and Mb*now <= bmax:
        if dp[N-1][Ma*now][Mb*now] < ans:
            ans = dp[N-1][Ma*now][Mb*now]
        now += 1
    else:
        break

if ans == 5000:
    print('-1')
else:
    print(ans)
# Original solution
n,ma,mb=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*n]

memo=[[10**5 for _ in [0]*401] for _ in [0]*401]
memo[0][0]=0

for N in range(n):
    for i in range(390,-1,-1):
        for j in range(390,-1,-1):
            a,b,c=abc[N]
            memo[i+a][j+b]=min(memo[i+a][j+b],memo[i][j]+c)

m=10**4
for i in range(1,400):
    for j in range(1,400):
        if i*mb==ma*j:
            m=min(m,memo[i][j])
if m==10**4:
    print((-1))
else:
    print(m)

# Optimized solution
n,ma,mb=list(map(int,input().split()))
abc=[list(map(int,input().split())) for _ in [0]*n]

memo=[[10**4 for _ in [0]*(n*10+1)] for _ in [0]*(n*10+1)]
memo[0][0]=0

for N in range(n):
    for i in range(N*10,-1,-1):
        for j in range(N*10,-1,-1):
            a,b,c=abc[N]
            memo[i+a][j+b]=min(memo[i+a][j+b],memo[i][j]+c)

m=10**4
for i in range(1,n*10):
    for j in range(1,n*10):
        if i*mb==ma*j:
            m=min(m,memo[i][j])
if m==10**4:
    print((-1))
else:
    print(m)