import sys



def solve():

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

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



    g1 = half_rekkyo(N, Ma, Mb, table, 0, N // 2)

    g2 = half_rekkyo(N, Ma, Mb, table, N // 2, N - N // 2)



    inf = 100 * 40 + 1

    ans = inf



    if 0 in g1:

        ans = min(ans, g1[0])

    if 0 in g2:

        ans = min(ans, g2[0])



    for v1, c1 in g1.items():

        if -v1 in g2:

            tmp = c1 + g2[-v1]

            ans = min(ans, tmp)



    if ans < inf:

        print(ans)

    else:

        print(-1)



def half_rekkyo(N, Ma, Mb, table, s, m):

    res = dict()



    for comb in range(1, 2**m):

        v = 0

        cost = 0



        for i in range(m):

            if comb & (1 << i):

                a, b, c = table[s + i]

                v += b * Ma - a * Mb

                cost += c



        if v in res:

            res[v] = min(res[v], cost)

        else:

            res[v] = cost



    return res



def debug(x, table):

    for name, val in table.items():

        if x is val:

            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)

            return None





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


def solve():
    N, Ma, Mb = map(int, input().split())
    table = [tuple(map(int, input().split())) for i in range(N)]
    g1 = half_rekkyo(N, Ma, Mb, table, 0, N // 2)
    g2 = half_rekkyo(N, Ma, Mb, table, N // 2, N - N // 2)
    inf = 100 * 40 + 1
    ans = inf
    if 0 in g1:
        ans = min(ans, g1[0])
    if 0 in g2:
        ans = min(ans, g2[0])
    for v1, c1 in g1.items():
        if -v1 in g2:
            tmp = c1 + g2[-v1]
            ans = min(ans, tmp)
    if ans < inf:
        print(ans)
    else:
        print(-1)


def half_rekkyo(N, Ma, Mb, table, s, m):
    res = dict()
    for comb in range(1, 2**m):
        v = 0
        cost = 0
        for i in range(m):
            if comb & (1 << i):
                a, b, c = table[s + i]
                v += b * Ma - a * Mb
                cost += c
        if v in res:
            res[v] = min(res[v], cost)
        else:
            res[v] = cost
    return res


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
            return None


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

-import sys - - -    N, Ma, Mb = map(int, input().split()) -    table = [tuple(map(int, input().split())) for i in range(N)] -    g1 = half_rekkyo(N, Ma, Mb, table, 0, N // 2) -    g2 = half_rekkyo(N, Ma, Mb, table, N // 2, N - N // 2) -    inf = 100 * 40 + 1 +    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]) -    if 0 in g1: -        ans = min(ans, g1[0]) -    if 0 in g2: -        ans = min(ans, g2[0]) -    for v1, c1 in g1.items(): -        if -v1 in g2: -            tmp = c1 + g2[-v1] -            ans = min(ans, tmp) +    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]) -        print(-1) - - -def half_rekkyo(N, Ma, Mb, table, s, m): -    res = dict() -    for comb in range(1, 2**m): -        v = 0 -        cost = 0 -        for i in range(m): -            if comb & (1 << i): -                a, b, c = table[s + i] -                v += b * Ma - a * Mb -                cost += c -        if v in res: -            res[v] = min(res[v], cost) -        else: -            res[v] = cost -    return res - - -def debug(x, table): -    for name, val in table.items(): -        if x is val: -            print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) -            return None +        print((-1))