CodeEff/ECCO huggingface dataset:
# 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()))

dp = [[[4001 for i in range(411)] for j in range(411)] for l in range(N+1)]

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

for i in range(1,N+1):
    for j in range(400):
        for k in range(400):
            dp[i][j+a[i-1]][k+b[i-1]] = min(dp[i-1][j][k] + c[i-1],dp[i-1][j+a[i-1]][k+b[i-1]])
            dp[i][j][k] = min(dp[i - 1][j][k], dp[i][j][k])
s = min(400//Ma,400//Mb)

min = 4001
for i in range(1,s+1):
    x = dp[N][i*Ma][i*Mb]
    if x>0 and min > x:
        min = x

if min != 4001:
    print(min)
else:
    print((-1))


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

dp = [[[4001 for i in range(411)] for j in range(411)] for l in range(N+1)]

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

for i in range(1,N+1):
    for j in range(400):
        for k in range(400):
            if dp[i-1][j][k] == 4001:
                continue
            dp[i][j+a[i-1]][k+b[i-1]] = min(dp[i-1][j][k] + c[i-1],dp[i-1][j+a[i-1]][k+b[i-1]])
            dp[i][j][k] = min(dp[i - 1][j][k], dp[i][j][k])
s = min(400//Ma,400//Mb)

min = 4001
for i in range(1,s+1):
    x = dp[N][i*Ma][i*Mb]
    if x>0 and min > x:
        min = x

if min != 4001:
    print(min)
else:
    print((-1))
# Original solution
n, ma, mb = list(map(int, input().split()))
N = 403
memo = [[10**18]*(N+20) for i in range(N+20)]
memo[0][0] = 0
for t in range(n):
    a, b, c = list(map(int, input().split()))
    for i in range(N, -1, -1):
        for j in range(N, -1, -1):
            memo[i+a][j+b] = min(memo[i+a][j+b], memo[i][j] + c)
ans = 10**18
a = ma; b = mb
while a < N and b < N:
    ans = min(ans, memo[a][b])
    a += ma; b += mb
print(-1 if ans > 50000 else ans)

# Optimized solution
from heapq import heappush, heappop
n, ma, mb = list(map(int, input().split()))
dp = {(0, 0): 0}
INF = 10**18
for i in range(n):
    a, b, c = list(map(int, input().split()))
    for x, y in sorted(dp.keys())[::-1]:
        dp[x+a, y+b] = min(dp.get((x+a, y+b), INF), dp[x, y] + c)
ans = INF
for x, y in dp:
    if x*mb == y*ma > 0:
        ans = min(ans, dp[x, y])
print(-1 if ans==INF else ans)
# Original solution
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M_a: int, M_b: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    t = [[float("inf")] * (10 * N + 1) for _ in range(10 * N + 1)]
    t[0][0] = 0
    for ai, bi, ci in zip(a, b, c):
        for ta in reversed(list(range(ai, len(t)))):
            for tb in reversed(list(range(bi, len(t[0])))):
                t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
    ans = min(
        t[k * M_a][k * M_b]
        for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
    )
    print((-1 if ans == float("inf") else ans))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M_a = int(next(tokens))  # type: int
    M_b = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    c = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M_a, M_b, a, b, c)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M_a: int, M_b: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    inf = 100000
    t = [[inf] * (10 * N + 1) for _ in range(10 * N + 1)]
    t[0][0] = 0
    for ai, bi, ci in zip(a, b, c):
        for ta in reversed(list(range(ai, len(t)))):
            for tb in reversed(list(range(bi, len(t[0])))):
                t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
    ans = min(
        t[k * M_a][k * M_b]
        for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
    )
    print((-1 if ans >= inf else ans))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M_a = int(next(tokens))  # type: int
    M_b = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    c = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M_a, M_b, a, b, c)


if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


N, M_a, M_b = [int(x) for x in input().split()]
inf = 100000
t = [[inf] * (10 * N + 1) for _ in range(10 * N + 1)]
t[0][0] = 0
for _ in range(N):
    ai, bi, ci = [int(x) for x in input().split()]
    for ta in reversed(list(range(ai, len(t)))):
        for tb in reversed(list(range(bi, len(t[0])))):
            t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
ans = min(
    t[k * M_a][k * M_b]
    for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
)
print((-1 if ans >= inf else ans))


# Optimized solution
#!/usr/bin/env python3
def solve():
    N, M_a, M_b = [int(x) for x in input().split()]
    inf = 100000
    t = [[inf] * (10 * N + 1) for _ in range(10 * N + 1)]
    t[0][0] = 0
    for _ in range(N):
        ai, bi, ci = [int(x) for x in input().split()]
        for ta in reversed(list(range(ai, len(t)))):
            for tb in reversed(list(range(bi, len(t[0])))):
                t[ta][tb] = min(t[ta][tb], t[ta - ai][tb - bi] + ci)
    ans = min(
        t[k * M_a][k * M_b]
        for k in range(1, min((len(t) - 1) // M_a, (len(t[0]) - 1) // M_b) + 1)
    )
    print((-1 if ans >= inf else ans))


solve()
# Original solution
import sys
input = sys.stdin.buffer.readline

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

INF = 10 ** 15
dp = [[INF for j in range(401)] for i in range(401)]
dp[0][0] = 0

for a, b, c in ABC:
  for i in range(400, -1, -1):
    for j in range(400, -1, -1):
      if dp[i][j] != INF:
        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

answer = INF
for i in range(1, 401):
  for j in range(1, 401):
    if dp[i][j] != INF and i / j == Ma / Mb:
      answer = min(answer, dp[i][j])
      
print((answer if answer != INF else -1))

# Optimized solution
import sys
input = sys.stdin.buffer.readline

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

sumA = sum([ABC[i][0] for i in range(N)])
sumB = sum([ABC[i][1] for i in range(N)])

INF = 10 ** 15
dp = [[INF for j in range(sumB + 1)] for i in range(sumA + 1)]
dp[0][0] = 0

for a, b, c in ABC:
  for i in range(sumA, -1, -1):
    for j in range(sumB, -1, -1):
      if dp[i][j] != INF:
        dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

answer = INF
for i in range(1, sumA + 1):
  for j in range(1, sumB + 1):
    if dp[i][j] != INF and i / j == Ma / Mb:
      answer = min(answer, dp[i][j])
      
print((answer if answer != INF else -1))
# Original solution
import itertools

N,MA,MB = list(map(int,input().split()))
arr = []

for i in range(N):
  l = list(map(int,input().split()))
  arr.append(l)
  
dp = [ [ [50000 for k in range(401)] for j in range(401)] for i in range(N+1) ]
dp[0][0][0] = 0

for i,a,b in itertools.product(list(range(1,N+1)),list(range(401)),list(range(401))):
  A = arr[i-1][0]
  B = arr[i-1][1]
  C = arr[i-1][2]
  
  if A <= a and B <= b:
    dp[i][a][b] = min(dp[i][a][b],dp[i-1][a-A][b-B] + C)
  else:
    dp[i][a][b] = dp[i-1][a][b]

ans = 50000
for i,a,b in itertools.product(list(range(N+1)),list(range(401)),list(range(401))):
  if a * MB == b ** MA and a != 0 and b != 0:
    ans = min(ans,dp[i][a][b])
if ans == 50000:
  print((-1))
else:
  print((int(ans)))

# Optimized solution
import itertools

N,MA,MB = list(map(int,input().split()))
arr = []

for i in range(N):
  l = list(map(int,input().split()))
  arr.append(l)
  
dp = [ [ [50000 for k in range(401)] for j in range(401)] for i in range(N+1) ]
dp[0][0][0] = 0
ans = 50000

for i,a,b in itertools.product(list(range(1,N+1)),list(range(401)),list(range(401))):
  A = arr[i-1][0]
  B = arr[i-1][1]
  C = arr[i-1][2]
  
  if A <= a and B <= b and dp[i-1][a-A][b-B] != 50000:
    dp[i][a][b] = min(dp[i-1][a][b],dp[i-1][a-A][b-B] + C)
  else:
    dp[i][a][b] = dp[i-1][a][b]

for a,b in itertools.product(list(range(401)),list(range(401))):
    if a * MB == b * MA and a != 0 and b != 0:
      ans = min(ans,dp[-1][a][b])
    
if ans == 50000:
  print((-1))
else:
  print((int(ans)))
# Original solution

def solve():
    N, Ma, Mb = list(map(int, input().split()))
    a, b, c = [], [], []

    for i in range(N):
        ai, bi, ci = list(map(int, input().split()))
        a.append(ai)
        b.append(bi)
        c.append(ci)

    alim = sum(a)
    blim = sum(b)
    inf = 40 * 100 + 1

    dp = [[inf]*(blim + 1) for i in range(alim + 1)]
    dp[0][0] = 0

    for i in range(N):
        for u in range(alim, a[i] - 1, -1):
            for v in range(blim, b[i] - 1, -1):
                dp[u][v] = min(dp[u][v], dp[u - a[i]][v - b[i]] + c[i])

    ans = inf

    for u in range(1, alim + 1):
        for v in range(1, blim + 1):
            if u * Mb == v * Ma:
                ans = min(ans, dp[u][v])

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

if __name__ == '__main__':
    solve()

# Optimized solution

def solve():
    N, Ma, Mb = list(map(int, input().split()))
    a, b, c = [], [], []

    for i in range(N):
        ai, bi, ci = list(map(int, input().split()))
        a.append(ai)
        b.append(bi)
        c.append(ci)

    nvals = 99 * N * 2 + 1
    inf = 40 * 100 + 1
    dp = [[inf] * nvals for i in range(N)]

    for i in range(N):
        v = Mb * a[i] - Ma * b[i]

        if i == 0:
            dp[i][v] = c[i]
            continue

        for j in range(-99 * N, 99 * N + 1):
            if -99 * N <= j - v <= 99 * N:
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + c[i])

        dp[i][v] = min(dp[i][v], c[i])

    ans = dp[N - 1][0]

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

if __name__ == '__main__':
    solve()
# Original solution

def solve():
    N, Ma, Mb = list(map(int, input().split()))
    a, b, c = [], [], []

    for i in range(N):
        ai, bi, ci = list(map(int, input().split()))
        a.append(ai)
        b.append(bi)
        c.append(ci)

    nvals = 99 * N * 2 + 1
    inf = 40 * 100 + 1
    dp = [[inf] * nvals for i in range(N)]

    for i in range(N):
        v = Mb * a[i] - Ma * b[i]

        if i == 0:
            dp[i][v] = c[i]
            continue

        for j in range(-99 * N, 99 * N + 1):
            if -99 * N <= j - v <= 99 * N:
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + c[i])

        dp[i][v] = min(dp[i][v], c[i])

    ans = dp[N - 1][0]

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

if __name__ == '__main__':
    solve()

# Optimized solution

def solve():
    N, Ma, Mb = list(map(int, input().split()))
    a, b, c = [], [], []

    for i in range(N):
        ai, bi, ci = list(map(int, input().split()))
        a.append(ai)
        b.append(bi)
        c.append(ci)

    nvals = 99 * N * 2 + 1
    inf = 40 * 100 + 1
    dp = [inf] * nvals

    for i in range(N):
        v = Mb * a[i] - Ma * b[i]

        if i == 0:
            dp[v] = c[i]
            continue

        if v > 0:
            for j in range(99 * N, -99 * N + v - 1, -1):
                dp[j] = min(dp[j], dp[j - v] + c[i])
        else:
            for j in range(-99 * N, 99 * N + v + 1):
                dp[j] = min(dp[j], dp[j - v] + c[i])

        dp[v] = min(dp[v], c[i])

    ans = dp[0]

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

if __name__ == '__main__':
    solve()
# Original solution
import copy

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

INF, W = 10 ** 10, 10 * 10 * N
dp = [[INF] * (2 * W + 1)]

for a, b, c in ABC:
    dp.append(copy.deepcopy(dp[-1]))
    df = a * Mb - b * Ma
    dp[-1][df] = min(c, dp[-1][df])
    for d in range(-W, W + 1):
        dp[-1][df + d] = min(c + dp[-2][d], dp[-1][df + d])

print(("-1" if dp[N][0] == INF else dp[N][0]))


# Optimized solution
import copy

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

INF, W = 10000, 10 * max(Ma, Mb) * N
dp = [[INF] * (2 * W + 1)]

for a, b, c in ABC:
    dp.append(copy.deepcopy(dp[-1]))
    df = a * Mb - b * Ma
    dp[-1][df] = min(dp[-1][df], c)
    for d in range(-W, W + 1):
        dp[-1][df + d] = min(dp[-1][df + d], c + dp[-2][d])

print(("-1" if dp[N][0] == INF else dp[N][0]))
# Original solution
import sys
inf = float('inf')
n, ma, mb = list(map(int, input().split()))
t = [[inf] * 401 for _ in range(401)]
for _ in range(n):
  a, b, c = list(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]
  if t[a][b] > c:
    t[a][b] = c
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)


# Optimized solution
import sys
inf = float('inf')
n, ma, mb = list(map(int, input().split()))
t = [[inf] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
  a, b, c = list(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)
# Original solution
nmax, abmax, inf = 40, 10, 1000000

a, b, c = [0] * nmax, [0] * nmax, [0] * nmax
dp = [[[0] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)] for _ in range(nmax + 1)]

n, ma, mb = list(map(int, input().split()))
for i in range(n):
  x, y, z = list(map(int, input().split()))
  a[i], b[i], c[i] = x, y, z

for i in range(n + 1):
  for ca in range(nmax * abmax + 1):
    for cb in range(nmax * abmax + 1):
      dp[i][ca][cb] = inf

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

for i in range(n):
  for ca in range(0, 401):
    for cb in range(0, 401):
      if dp[i][ca][cb] == inf:
        continue
      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 = inf
for ca in range(1, 401):
  for cb in range(1, 401):
    if ca * mb == cb * ma:
      ans = min(ans, dp[n][ca][cb])

if ans == inf:
  ans = -1

print(ans)


# Optimized solution
nmax, abmax, inf = 40, 10, 1000000

dp = [[[inf] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)] for _ in range(nmax + 1)]

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

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

for i in range(n):
  a, b, c = list(map(int, input().split()))
  dpi = dp[i]
  dpi1 = dp[i + 1]
  for ca in range(0, 401):
    for cb in range(0, 401):
      if dpi[ca][cb] == inf:
        continue
      dpi1[ca][cb] = min(dpi1[ca][cb], dpi[ca][cb])
      dpi1[ca + a][cb + b] = min(dpi1[ca + a][cb + b], dpi[ca][cb] + c)

ans = inf
dpn = dp[n]
for ca in range(1, 401):
  for cb in range(1, 401):
    if ca * mb == cb * ma:
      ans = min(ans, dpn[ca][cb])

if ans == inf:
  ans = -1

print(ans)
# Original solution
nmax, abmax, inf = 40, 10, 1000000

dp = [[[inf] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)] for _ in range(nmax + 1)]

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

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

for i in range(n):
  a, b, c = list(map(int, input().split()))
  dpi = dp[i]
  dpi1 = dp[i + 1]
  for ca in range(0, 401):
    for cb in range(0, 401):
      if dpi[ca][cb] == inf:
        continue
      dpi1[ca][cb] = min(dpi1[ca][cb], dpi[ca][cb])
      dpi1[ca + a][cb + b] = min(dpi1[ca + a][cb + b], dpi[ca][cb] + c)

ans = inf
dpn = dp[n]
for ca in range(1, 401):
  for cb in range(1, 401):
    if ca * mb == cb * ma:
      ans = min(ans, dpn[ca][cb])

if ans == inf:
  ans = -1

print(ans)


# Optimized solution
INF = float('inf')
n, ma, mb = list(map(int, input().split()))
t = [[INF] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
  a, b, c = list(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] > t[aa][bb] + c:
        t[a + aa][b + bb] = t[aa][bb] + c
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:
  result = -1
print(result)
# Original solution
INF = float('inf')
n, ma, mb = list(map(int, input().split()))
t = [[INF] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
  a, b, c = list(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] > t[aa][bb] + c:
        t[a + aa][b + bb] = t[aa][bb] + c
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:
  result = -1
print(result)


# Optimized solution
INF = float('inf')
MAXAB = 10
n, ma, mb = list(map(int, input().split()))
t = [[INF] * (n * MAXAB + 1) for _ in range(n * MAXAB + 1)]
t[0][0] = 0
for _ in range(n):
  a, b, c = list(map(int, input().split()))
  for aa in range(n * MAXAB, -1, -1):
    for bb in range(n * MAXAB, -1, -1):
      if t[aa][bb] == INF:
        continue
      if t[a + aa][b + bb] > t[aa][bb] + c:
        t[a + aa][b + bb] = t[aa][bb] + c
result = INF
for a in range(1, n * MAXAB + 1):
  for b in range(1, n * MAXAB + 1):
    if a * mb == b * ma and result > t[a][b]:
      result = t[a][b]
if result == INF:
  result = -1
print(result)
# Original solution
n,ma,mb=list(map(int,input().split()))
abc=[]
for i in range(n):
    abc.append([int(j) for j in input().split()])
from operator import itemgetter
abc.sort(key=itemgetter(2))

dp=[[10**18 for i in range(401)]for j in range(401)]
dp[0][0]=0

q=[[0,0]]
for a,b,c in abc:
    l=[]
    for i,j in q:
        l.append([i,j])
        l.append([i+a,j+b])
        dp[a+i][b+j]=min(dp[a+i][b+j],dp[i][j]+c)
    q=l

ans=1145141919
i=1
while ma*i<401 and mb*i<401:
    ans=min(ans,dp[ma*i][mb*i])
    i+=1
if ans==1145141919:
    print((-1))
else:
    print(ans)





# Optimized solution
n,ma,mb=list(map(int,input().split()))
abc=[]
for i in range(n):
    abc.append([int(j) for j in input().split()])
from operator import itemgetter
abc.sort(key=itemgetter(2))

dp=[[10**18 for i in range(401)]for j in range(401)]
dp[0][0]=0

p,q=0,0
for a,b,c in abc:
    for j in reversed(list(range(q+1))):
        for i in range(p+1):
            if dp[i][j]==10**18:
                continue
            else:
                dp[i+a][j+b]=min(dp[i+a][j+b],dp[i][j]+c)
    p+=a
    q+=b

ans=1145141919
i=1
while ma*i<401 and mb*i<401:
    ans=min(ans,dp[ma*i][mb*i])
    i+=1
if ans==1145141919:
    print((-1))
else:
    print(ans)
# Original solution
#!/usr/bin/env python3

from copy import deepcopy

ABMAX = 400
HUGE = 10 ** 12

def main():
    n, ma, mb = list(map(int, input().split()))
    sold = []
    for i in range(n):
        a, b, c = list(map(int, input().split()))
        sold.append((a, b, c))
    mincost = dp(sold, n)
    print((find_mincost(mincost, ma, mb)))

def find_mincost(mincost, ma, mb):
    for mult in range(1, ABMAX):
        if ma * mult > ABMAX:
            break
        if mb * mult > ABMAX:
            break
        if mincost[ma * mult][mb * mult] < HUGE:
            return mincost[ma * mult][mb * mult]
    return -1

def dp(sold, n):
    # mincost[a][b]: Minimum cost of achieving a, b
    mincost = [[HUGE for b in range(ABMAX + 1)] for a in range(ABMAX + 1)]
    mincost[0][0] = 0
    for a, b, c in sold:
        mincost = update(mincost, a, b, c)
    return mincost

def update(prevcost, a, b, c):
    mincost = deepcopy(prevcost)
    for ia in range(ABMAX + 1):  # 配る
        for ib in range(ABMAX + 1):
            na = ia + a
            nb = ib + b
            if na <= ABMAX and nb <= ABMAX:
                mincost[na][nb] = min(mincost[na][nb], prevcost[ia][ib] + c)
    return mincost

main()


# Optimized solution
#!/usr/bin/env python3

from copy import deepcopy

ABMAX = 400
HUGE = 10 ** 12

def main():
    n, ma, mb = list(map(int, input().split()))
    sold = []
    for i in range(n):
        a, b, c = list(map(int, input().split()))
        sold.append((a, b, c))
    mincost = dp(sold, n)
    print((find_mincost(mincost, ma, mb)))

def find_mincost(mincost, ma, mb):
    res = HUGE
    for mult in range(1, ABMAX):
        if ma * mult > ABMAX:
            break
        if mb * mult > ABMAX:
            break
        res = min(res, mincost[ma * mult][mb * mult])
    return -1 if res == HUGE else res

def dp(sold, n):
    # mincost[a][b]: Minimum cost of achieving a, b
    mincost = [[HUGE for b in range(ABMAX + 1)] for a in range(ABMAX + 1)]
    mincost[0][0] = 0
    for a, b, c in sold:
        mincost = update(mincost, a, b, c)
    return mincost

def update(prevcost, a, b, c):
    mincost = deepcopy(prevcost)
    for ia in range(ABMAX + 1):  # 配る
        for ib in range(ABMAX + 1):
            na = ia + a
            nb = ib + b
            if na <= ABMAX and nb <= ABMAX:
                mincost[na][nb] = min(mincost[na][nb], prevcost[ia][ib] + c)
    return mincost

main()
# Original solution
N,Ma,Mb=list(map(int,input().split()))
Med=[]
for i in range(N):
  a=[int(x) for x in input().split()]
  Med.append(a)
  
#[i]まででMa=[j],Mb=[k]を作る場合の最小のコストdp
#dp[i+1][j+Ma][k+Mb]=min(dp[i][j+Ma][k+Mb],dp[i][j][k]+Cost)
#リストをinfで初期化。inf=作れない配合なので、continue。初期値はdp[0][0][0]=0
dp=[[[float('inf') for j in range(401)] for k in range(401)] for i 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 dp[i][j][k]==float('inf'):
        continue
      dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k])
      dp[i+1][j+Med[i][0]][k+Med[i][1]]=min(dp[i][j+Med[i][0]][k+Med[i][1]],dp[i][j][k]+Med[i][2])

ans=float('inf')
for i in range(1,N+1):
  if i*Ma<401 and i*Mb<401:
    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()))
Med=[]
cnt_a=0
cnt_b=0
for i in range(N):
  a=[int(x) for x in input().split()]
  Med.append(a)
  cnt_a+=a[0]
  cnt_b+=a[1]
R=max(cnt_a,cnt_b)
#[i]まででMa=[j],Mb=[k]を作る場合の最小のコストdp
#dp[i+1][j+Ma][k+Mb]=min(dp[i][j+Ma][k+Mb],dp[i][j][k]+Cost)
#リストをinfで初期化。inf=作れない配合なので、continue。初期値はdp[0][0][0]=0
dp=[[[float('inf') for j in range(R+1)] for k in range(R+1)] for i in range(N+1)]
dp[0][0][0]=0

for i in range(N):
  for j in range(R+1):
    for k in range(R+1):
      if dp[i][j][k]==float('inf'):
        continue
      dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k])
      dp[i+1][j+Med[i][0]][k+Med[i][1]]=min(dp[i][j+Med[i][0]][k+Med[i][1]],dp[i][j][k]+Med[i][2])

ans=float('inf')
for i in range(1,N+1):
  if i*Ma<R+1 and i*Mb<R+1:
    ans=min(ans,dp[N][i*Ma][i*Mb])
if ans==float('inf'):
  print((-1))
else:
  print(ans)