

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)



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

-    dp = [[inf] * nvals for i in range(N)] +    dp = [inf] * nvals -            dp[i][v] = c[i] +            dp[v] = c[i] -        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 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]