def main():

    INF = 100 * 40 + 1

    MX = 4000



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



    dp = [[INF] * (MX * 2 + 1) for _ in range(2)]

    i, j = 0, 1

    for _ in range(N):

        ai, bi, ci = list(map(int, input().split()))

        x = Ma * bi - Mb * ai  # Σai:Σbi=Ma:Mb<->Ma*Σbi-Mb*Σai=0



        for k in range(-MX, MX + 1):

            dp[j][k] = dp[i][k]

        dp[j][x] = min(dp[j][x], ci)



        for k in range(-MX + x, MX + 1):

            dp[j][k] = min(

                dp[j][k],

                dp[i][k - x] + ci

            )

        i, j = j, i



    res = dp[i][0]

    print((-1 if res == INF else res))





if __name__ == '__main__':

    main()

# https://atcoder.jp/contests/abc054/submissions/4360181



def main():

    from collections import defaultdict



    INF = 40 * 100 + 1



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



    memo = defaultdict(lambda: INF)



    for _ in range(N):

        ai, bi, ci = list(map(int, input().split()))

        x = Ma * bi - Mb * ai  # Σai:Σbi=Ma:Mb<->Ma*Σbi-Mb*Σai=0



        for key, value in tuple(memo.items()):

            memo[key + x] = min(

                memo[key + x],

                value + ci

            )  # 既存の組み合わせに混合

        memo[x] = min(memo[x], ci)  # 新規のみ



    print((memo[0] if 0 in memo else -1))





if __name__ == '__main__':

    main()

def main():
    INF = 100 * 40 + 1
    MX = 4000
    N, Ma, Mb = list(map(int, input().split()))
    dp = [[INF] * (MX * 2 + 1) for _ in range(2)]
    i, j = 0, 1
    for _ in range(N):
        ai, bi, ci = list(map(int, input().split()))
        x = Ma * bi - Mb * ai  # Σai:Σbi=Ma:Mb<->Ma*Σbi-Mb*Σai=0
        for k in range(-MX, MX + 1):
            dp[j][k] = dp[i][k]
        dp[j][x] = min(dp[j][x], ci)
        for k in range(-MX + x, MX + 1):
            dp[j][k] = min(dp[j][k], dp[i][k - x] + ci)
        i, j = j, i
    res = dp[i][0]
    print((-1 if res == INF else res))


if __name__ == "__main__":
    main()

# https://atcoder.jp/contests/abc054/submissions/4360181
def main():
    from collections import defaultdict

    INF = 40 * 100 + 1
    N, Ma, Mb = list(map(int, input().split()))
    memo = defaultdict(lambda: INF)
    for _ in range(N):
        ai, bi, ci = list(map(int, input().split()))
        x = Ma * bi - Mb * ai  # Σai:Σbi=Ma:Mb<->Ma*Σbi-Mb*Σai=0
        for key, value in tuple(memo.items()):
            memo[key + x] = min(memo[key + x], value + ci)  # 既存の組み合わせに混合
        memo[x] = min(memo[x], ci)  # 新規のみ
    print((memo[0] if 0 in memo else -1))


if __name__ == "__main__":
    main()

+# https://atcoder.jp/contests/abc054/submissions/4360181 -    INF = 100 * 40 + 1 -    MX = 4000 +    from collections import defaultdict + +    INF = 40 * 100 + 1 -    dp = [[INF] * (MX * 2 + 1) for _ in range(2)] -    i, j = 0, 1 +    memo = defaultdict(lambda: INF) -        for k in range(-MX, MX + 1): -            dp[j][k] = dp[i][k] -        dp[j][x] = min(dp[j][x], ci) -        for k in range(-MX + x, MX + 1): -            dp[j][k] = min(dp[j][k], dp[i][k - x] + ci) -        i, j = j, i -    res = dp[i][0] -    print((-1 if res == INF else res)) +        for key, value in tuple(memo.items()): +            memo[key + x] = min(memo[key + x], value + ci)  # 既存の組み合わせに混合 +        memo[x] = min(memo[x], ci)  # 新規のみ +    print((memo[0] if 0 in memo else -1))