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[401][401][41];
    foreach (i; 0..41) {
        foreach (j; 0..401) {
            foreach (k; 0..401) {
                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..401) {
            foreach (cb; 0..401) {
                if (dp[i-1][ca][cb] == 114514) continue;
                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..401) {
        foreach (cb; 1..401) {
            if (ca * Mb == cb * Ma) res = min(res, dp[N][ca][cb]);
        }
    }
    if (res == 114514) res = -1;
    writeln(res);
}