

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


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

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

-    alim = sum(a) -    blim = sum(b) +    nvals = 99 * N * 2 + 1 -    dp = [[inf] * (blim + 1) for i in range(alim + 1)] -    dp[0][0] = 0 +    dp = [[inf] * nvals 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]) +        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]