import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum mod = 10L^^9 + 7;
enum inf = 10^^9;

void main() {
    int n, ma, mb;
    scan(n, ma, mb);
    auto a = new int[](n);
    auto b = new int[](n);
    auto c = new int[](n);
    foreach (i ; 0 .. n) {
        scan(a[i], b[i], c[i]);
    }
    auto dp = new int[][][](n + 1, 401, 401);
    fillAll(dp, inf);
    dp[0][0][0] = 0;

    foreach (i ; 1 .. n + 1) {
        foreach (ag ; 0 .. 401) {
            foreach (bg ; 0 .. 401) {
                dp[i][ag][bg] = dp[i-1][ag][bg];
                if (ag - a[i-1] >= 0 && bg - b[i-1] >= 0) {
                    dp[i][ag][bg] = min(dp[i][ag][bg],
                        dp[i-1][ag - a[i-1]][bg - b[i-1]] + c[i-1]);
                }
            }
        }
    }

    long ans = inf;
    int aa = ma, bb = mb;

    while (aa <= 400 && bb <= 400) {
        debug {
            writeln(dp[n][aa][bb]);
        }
        ans = min(ans, dp[n][aa][bb]);
        aa += ma;
        bb += mb;
    }

    writeln(ans < inf ? ans : -1);
}























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}