import std.stdio, std.string, std.conv, std.range, std.algorithm;

void main() {
    auto S = readln.split.to!(int[]);
    auto N = S[0], Ma = S[1], Mb = S[2];
    auto data = new int[3][N];
    foreach (i; 0..N) {
        data[i] = readln.split.to!(int[]);
    }
    auto dp = new int[40][400][400];
    foreach (i; 0..N+1) {
        foreach (j; 0..10 * N) {
            foreach (k; 0..10 * N) {
                dp[i][j][k] = 114514;
            }
        }
    }
    dp[0][0][0] = 0;
    foreach (i; 1..N+1) {
        auto a = data[i-1][0];
        auto b = data[i-1][1];
        auto c = data[i-1][2];
        foreach (ca; 0..10 * N) {
            foreach (cb; 0..10 * N) {
                dp[i][ca][cb] = min(dp[i-1][ca][cb], dp[i][ca][cb]);
                dp[i][ca+a][cb+b] = min(dp[i-1][ca][cb] + c, dp[i][ca+a][cb+b]);
            }
        }
    }
    auto res = 114514;
    foreach (ca; 1..10 * N) {
        foreach (cb; 1..10 * N) {
            if (ca * Mb == cb * Ma) res = min(res, dp[N][ca][cb]);
        }
    }
    if (res == 114514) res = -1;
    writeln(res);
}