import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

alias sread = () => readln.chomp();

void main()
{
    int[] nmm = aryread!int();
    int N = nmm[0];
    int MA = nmm[1];
    int MB = nmm[2];

    int[] A, B, C;

    foreach (_; 0 .. N)
    {
        int[] abc = aryread!int();
        A ~= abc[0];
        B ~= abc[1];
        C ~= abc[2];
    }

    auto dp = new int[][][](N + 1, N * 11 + 1, N * 11 + 1);
    foreach (ref n; dp[0 .. $])
        foreach (ref row; n)
            row[] = int.max;
    dp[0][0][0] = 0;

    foreach (n; 0 .. N)
        foreach (a; 0 .. N * 10 + 1)
            foreach (b; 0 .. N * 10 + 1)
            {
                if (dp[n][a][b] != int.max)
                {
                    dp[n + 1][a + A[n]][b + B[n]] = min(dp[n + 1][a + A[n]][b + B[n]],
                            dp[n][a][b] + C[n]);
                }
                dp[n + 1][a][b] = min(dp[n + 1][a][b], dp[n][a][b]);
            }

    int ma = MA;
    int mb = MB;
    int result = int.max;
    while (ma < N * 10 + 1 && mb < N * 10 + 1)
    {
        if (dp[N][ma][mb] != 0)
        {
            result = result.min(dp[N][ma][mb]);
        }
        ma += MA;
        mb += MB;
    }
    // writeln(dp[N]);
    writeln(result == int.max ? -1 : result);
}
