import sys



INF = float('inf')



n, ma, mb = list(map(int, sys.stdin.readline().split()))

a, b, c = [], [], []

for _ in range(n):

    ai, bi, ci = list(map(int, sys.stdin.readline().split()))

    a.append(ai); b.append(bi); c.append(ci)



def main():

    sa = sum(a)

    sb = sum(b)

    res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)]

    res[0][0][0] = 0

    for i in range(n):

        for j in range(sa + 1):

            for k in range(sb + 1):

                if j >= a[i] and k >= b[i]:

                    res[i+1][j][k] = min(res[i][j-a[i]][k-b[i]] + c[i], res[i][j][k])

                else:

                    res[i+1][j][k] = res[i][j][k]

    ans = INF

    for i in range(1, min(sa//ma, sb//mb)+1):

        ans = min(ans, res[n][ma * i][mb * i])

    

    if ans == INF:

        return -1

    else:

        return ans



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys

import numpy as np



I = np.array(sys.stdin.read().split(), dtype=np.int64)

n, ma, mb = I[:3]

abc = I[3:].reshape(n, 3)



def main():

    sa, sb = np.sum(abc, axis=0)[:2]

    res = np.full((sa+1, sb+1), np.inf)

    res[0, 0] = 0



    for a, b, c in abc:

        res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c)

    

    ans = np.inf

    for i in range(1, min(sa//ma, sb//mb) + 1):

        ans = np.minimum(ans, res[ma * i, mb * i])

    

    if ans == np.inf:

        return -1

    return int(ans)

    

if __name__ == '__main__':

    ans = main()

    print(ans)
import sys

INF = float("inf")
n, ma, mb = list(map(int, sys.stdin.readline().split()))
a, b, c = [], [], []
for _ in range(n):
    ai, bi, ci = list(map(int, sys.stdin.readline().split()))
    a.append(ai)
    b.append(bi)
    c.append(ci)


def main():
    sa = sum(a)
    sb = sum(b)
    res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)]
    res[0][0][0] = 0
    for i in range(n):
        for j in range(sa + 1):
            for k in range(sb + 1):
                if j >= a[i] and k >= b[i]:
                    res[i + 1][j][k] = min(
                        res[i][j - a[i]][k - b[i]] + c[i], res[i][j][k]
                    )
                else:
                    res[i + 1][j][k] = res[i][j][k]
    ans = INF
    for i in range(1, min(sa // ma, sb // mb) + 1):
        ans = min(ans, res[n][ma * i][mb * i])
    if ans == INF:
        return -1
    else:
        return ans


if __name__ == "__main__":
    ans = main()
    print(ans)

import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, ma, mb = I[:3]
abc = I[3:].reshape(n, 3)


def main():
    sa, sb = np.sum(abc, axis=0)[:2]
    res = np.full((sa + 1, sb + 1), np.inf)
    res[0, 0] = 0
    for a, b, c in abc:
        res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c)
    ans = np.inf
    for i in range(1, min(sa // ma, sb // mb) + 1):
        ans = np.minimum(ans, res[ma * i, mb * i])
    if ans == np.inf:
        return -1
    return int(ans)


if __name__ == "__main__":
    ans = main()
    print(ans)

+import numpy as np -INF = float("inf") -n, ma, mb = list(map(int, sys.stdin.readline().split())) -a, b, c = [], [], [] -for _ in range(n): -    ai, bi, ci = list(map(int, sys.stdin.readline().split())) -    a.append(ai) -    b.append(bi) -    c.append(ci) +I = np.array(sys.stdin.read().split(), dtype=np.int64) +n, ma, mb = I[:3] +abc = I[3:].reshape(n, 3) -    sa = sum(a) -    sb = sum(b) -    res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)] -    res[0][0][0] = 0 -    for i in range(n): -        for j in range(sa + 1): -            for k in range(sb + 1): -                if j >= a[i] and k >= b[i]: -                    res[i + 1][j][k] = min( -                        res[i][j - a[i]][k - b[i]] + c[i], res[i][j][k] -                    ) -                else: -                    res[i + 1][j][k] = res[i][j][k] -    ans = INF +    sa, sb = np.sum(abc, axis=0)[:2] +    res = np.full((sa + 1, sb + 1), np.inf) +    res[0, 0] = 0 +    for a, b, c in abc: +        res[a:, b:] = np.minimum(res[a:, b:], res[:-a, :-b] + c) +    ans = np.inf -        ans = min(ans, res[n][ma * i][mb * i]) -    if ans == INF: +        ans = np.minimum(ans, res[ma * i, mb * i]) +    if ans == np.inf: -    else: -        return ans +    return int(ans)