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

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



N_max = 40

a_max = 10

b_max = 10

c_max = 100



inf = N_max * c_max + 1

dp = [[inf] * (N_max * b_max + 1) for _ in range(N_max * a_max + 1)]

dp[0][0] = 0



for i, (aa, bb, cc) in enumerate(e):

    for a in reversed(list(range(a_max * i + 1))):

        for b in reversed(list(range(b_max * i + 1))):

            if dp[a][b] == inf: continue

            if a + aa < N_max * a_max + 1 and b + bb < N_max * b_max + 1:

                dp[a + aa][b + bb] = min(dp[a + aa][b + bb], dp[a][b] + cc)



ans = inf

for i in range(1, N_max * a_max + 1):

    if i * Ma >= N_max * a_max + 1 or i * Mb >= N_max * b_max + 1: break

    # a:b=Ma:Mb

    # b*Ma=a*Mb

    ans = min(ans, dp[i * Ma][i * Mb])



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

inf = float('inf')



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

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

dp[0][0] = 0



max_a = 0

max_b = 0

for i in range(N):

    a, b, c = list(map(int, input().split()))

    max_a += a

    max_b += b

    for j in reversed(list(range(max_a + 1 - a))):

        for k in range(max_b + 1 - b):

            if dp[j][k] == inf: continue

            dp[j + a][k + b] = min(dp[j][k] + c, dp[j + a][k + b])



j = Ma

k = Mb

ans = inf

while j < 400 + 1 and k < 400 + 1:

    ans = min(ans, dp[j][k])

    j += Ma

    k += Mb



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

# print(dp)

N, Ma, Mb = list(map(int, input().split()))
e = [tuple(map(int, input().split())) for _ in range(N)]
N_max = 40
a_max = 10
b_max = 10
c_max = 100
inf = N_max * c_max + 1
dp = [[inf] * (N_max * b_max + 1) for _ in range(N_max * a_max + 1)]
dp[0][0] = 0
for i, (aa, bb, cc) in enumerate(e):
    for a in reversed(list(range(a_max * i + 1))):
        for b in reversed(list(range(b_max * i + 1))):
            if dp[a][b] == inf:
                continue
            if a + aa < N_max * a_max + 1 and b + bb < N_max * b_max + 1:
                dp[a + aa][b + bb] = min(dp[a + aa][b + bb], dp[a][b] + cc)
ans = inf
for i in range(1, N_max * a_max + 1):
    if i * Ma >= N_max * a_max + 1 or i * Mb >= N_max * b_max + 1:
        break
    # a:b=Ma:Mb
    # b*Ma=a*Mb
    ans = min(ans, dp[i * Ma][i * Mb])
print((ans if ans < inf else -1))

inf = float("inf")
N, Ma, Mb = list(map(int, input().split()))
dp = [[inf] * (400 + 1) for _ in range(400 + 1)]
dp[0][0] = 0
max_a = 0
max_b = 0
for i in range(N):
    a, b, c = list(map(int, input().split()))
    max_a += a
    max_b += b
    for j in reversed(list(range(max_a + 1 - a))):
        for k in range(max_b + 1 - b):
            if dp[j][k] == inf:
                continue
            dp[j + a][k + b] = min(dp[j][k] + c, dp[j + a][k + b])
j = Ma
k = Mb
ans = inf
while j < 400 + 1 and k < 400 + 1:
    ans = min(ans, dp[j][k])
    j += Ma
    k += Mb
print((-1 if ans == inf else ans))
# print(dp)

+inf = float("inf") -e = [tuple(map(int, input().split())) for _ in range(N)] -N_max = 40 -a_max = 10 -b_max = 10 -c_max = 100 -inf = N_max * c_max + 1 -dp = [[inf] * (N_max * b_max + 1) for _ in range(N_max * a_max + 1)] +dp = [[inf] * (400 + 1) for _ in range(400 + 1)] -for i, (aa, bb, cc) in enumerate(e): -    for a in reversed(list(range(a_max * i + 1))): -        for b in reversed(list(range(b_max * i + 1))): -            if dp[a][b] == inf: +max_a = 0 +max_b = 0 +for i in range(N): +    a, b, c = list(map(int, input().split())) +    max_a += a +    max_b += b +    for j in reversed(list(range(max_a + 1 - a))): +        for k in range(max_b + 1 - b): +            if dp[j][k] == inf: -            if a + aa < N_max * a_max + 1 and b + bb < N_max * b_max + 1: -                dp[a + aa][b + bb] = min(dp[a + aa][b + bb], dp[a][b] + cc) +            dp[j + a][k + b] = min(dp[j][k] + c, dp[j + a][k + b]) +j = Ma +k = Mb -for i in range(1, N_max * a_max + 1): -    if i * Ma >= N_max * a_max + 1 or i * Mb >= N_max * b_max + 1: -        break -    # a:b=Ma:Mb -    # b*Ma=a*Mb -    ans = min(ans, dp[i * Ma][i * Mb]) -print((ans if ans < inf else -1)) +while j < 400 + 1 and k < 400 + 1: +    ans = min(ans, dp[j][k]) +    j += Ma +    k += Mb +print((-1 if ans == inf else ans)) +# print(dp)