// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define incant() cin.tie(0), ios::sync_with_stdio(false)

#define int long long

#define uint unsigned long long

#define double long double

using str = string;

template <class T> using vec = vector<T>;

template <class T> using vvec = vec<vec<T>>;

template <class T> using que = queue<T>;

template <class T> using pque = priority_queue<T>;

template <class... T> using tup = tuple<T...>;

using vint = vec<int>;

using vvint = vvec<int>;

using vstr = vec<str>;

using pint = pair<int, int>;

using vp = vec<pint>;

using tll = tup<int, int, int>;

using vt = vec<tll>;

using mint = map<int, int>;

using dict = map<str, int>;

using qint = que<int>;

using qp = que<pint>;

using pqint = pque<int>;

using pqp = pque<pint>;

#define pb push_back

#define pob pop_back

#define pf push_front

#define pof pop_front

#define mp make_pair

#define mt make_tuple

#define ms memset

#define fir first

#define sec second

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define sz(x) x.size()

#define all(x) begin(x), end(x)

#define rall(x) rbegin(x), rend(x)

#define _overload3(_1, _2, _3, name, ...) name

#define _rep(i, n) repi(i, 0, n)

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)

#define _rev(i, n) revi(i, n, 0)

#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)

#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)

#define each(i, n) for(auto&& i: n)

#define out(x) cout << (x)

#define indent() cout << '\n'

#define print(x) out(x), indent()

#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'

#define YN(x) print((x) ? "YES" : "NO")

#define Yn(x) print((x) ? "Yes" : "No")

#define yn(x) print((x) ? "yes" : "no")

#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")

#define Pos(x) print((x) ? "Possible" : "Impossible")

#define pos(x) print((x) ? "possible" : "impossible")

int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}

int lcm(int a, int b){return a / gcd(a, b) * b;}

int factorial(int a){return a < 2 ? 1 : factorial(a - 1) * a;}

int summation(int a){return a < 1 ? 0 : (a * a + a) / 2;}

const int INF = 1e16, MOD = 1e9 + 7;

const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, -1, 0, 1};

const int dx8[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy8[] = {-1, -1, -1, 0, 0, 1, 1, 1};

const double EPS = 1e-9;

const str alphabet = "abcdefghijklmnopqrstuvwxyz";

int n, m, x, y, z, w, h;

str s, t;



signed main(){

    incant();

    while(cin >> n >> x >> y){

        int res = 0, cnt = 0, mx = -INF, mn = INF, a[n] = {}, b[n] = {}, c[n] = {};

        bool flag = true;

        int dp[n + 1][n * 10 + 1][n * 10 + 1]; //i番目まででhグラム、kグラムをませるときに必要な最小金額

        rep(i, n){

            cin >> a[i] >> b[i] >> c[i];

        }

        rep(i, n + 1){

            rep(j, n * 10 + 1){

                rep(k, n * 10 + 1){

                    dp[i][j][k] = INF;

                }

            }

        }

        dp[0][0][0] = 0;

        rep(i, n){

            rep(j, n * 10 + 1){

                rep(k, n * 10 + 1){

                    if(dp[i][j][k] != INF){

                        chmin(dp[i + 1][j][k], dp[i][j][k]);

                        chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);

                    }

                }

            }

        }

        rep(i, 1, n * 10 + 1){

            rep(j, 1, n * 10 + 1){

                if(i * y == j * x){

                    chmin(mn, dp[n][i][j]);

                }

            }

        }

        if(mn == INF){

            print(-1);

        }else{

            print(mn);

        }

    }

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define incant() cin.tie(0), ios::sync_with_stdio(false)

#define int long long

#define double long double

#define pb push_back

#define mp make_pair

#define mt make_tuple

#define lb lower_bound

#define ub upper_bound

#define F first

#define S second

#define gcd __gcd

template<class T> using pque = priority_queue<T>;

using vint = vector<int>;

using vstr = vector<string>;

using pint = pair<int, int>;

using ppi = pair<int, pint>;

using vp = vector<pint>;

using vppi = vector<ppi>;

using mint = map<int, int>;

using mpi = map<int, pint>;

using dict = map<string, int>;

using sint = set<int>;

using sp = set<pint>;

using qint = queue<int>;

using qp = queue<pint>;

using pqint = pque<int>;

using pqp = pque<pint>;

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define sz(x) x.size()

#define all(x) (x).begin(), (x).end()

#define _overload(_1, _2, _3, name, ...) name

#define _rep(i, n) repi(i, 0, n)

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)

#define rep(...) _overload(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)

#define _rev(i, n) revi(i, n, 0)

#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)

#define rev(...) _overload(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)

#define each(i, n) for(auto&& i: n)

#define inv(x) each(i, x) in(i)

#define out(x) cout << (x)

#define space() cout << " "

#define indent() cout << '\n'

#define printv(x) each(i, x) out(i), space(); indent()

#define debug(x, ...) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'

#define YN(x) print((x) ? "YES" : "NO")

#define Yn(x) print((x) ? "Yes" : "No")

#define yn(x) print((x) ? "yes" : "no")

#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")

#define Pos(x) print((x) ? "Possible" : "Impossible")

#define pos(x) print((x) ? "possible" : "impossible")

void in(){}

template<typename F, typename... R> void in(F& f, R&... r){

    cin >> f, in(r...);

}

void print(){

    indent();

}

template<typename F, typename... R> void print(F& f, R&... r){

    out(f), space(), print(r...);

}

const int INF = 1e16, MOD = 1e9 + 7, LIMIT = 100001, S_LIMIT = 101;

const int dx[] = {0, 0, 1, 0, -1, -1, 1, 1, -1}, dy[] = {0, -1, 0, 1, 0, -1, -1, 1, 1};

const string alphabet = "abcdefghijklmnopqrstuvwxyz";

const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int g[S_LIMIT][S_LIMIT] = {};

int lcm(int a, int b){

    return a/gcd(a, b)*b;

}

int modpw(int x, int n){

    return n < 2 ? x : modpw(x*x%MOD, n/2)*(n%2 ? x : 1)%MOD;

}

int factorial(int a){

    return a < 2 ? 1 : factorial(a - 1)*a;

}

int summation(int a){

    return a < 1 ? 0 : (a*a + a)/2;

}

int combination(int n, int r){

    int res = 1;

    rep(i, 1, r + 1){

        res *= n--, res /= i;

    }

    return res;

}

int modcomb(int n, int r){

    return factorial(n)*modpw(factorial(r), MOD - 2)%MOD*modpw(factorial(n - r), MOD - 2)%MOD;

}

bool isPrime(int n){

    rep(i, 2, sqrt(n) + 1){

        if(i > 3){

            i++;

        }

        if(!(n%i)){

            return false;

        }

    }

    return true;

}

void warshall(int n){

    rep(i, n){

        rep(j, n){

            rep(k, n){

                chmin(g[j][k], g[j][i] + g[i][k]);

            }

        }

    }

}

mint factorization(int n){

    mint ans;

    rep(i, 2, sqrt(n) + 1){

        if(i > 3){

            i++;

        }

        while(!(n%i)){

            ans[i]++, n /= i;

        }

    }

    if(n > 1){

        ans[n]++;

    }

    return ans;

}

struct UF{

    vint t;

    UF(int size): t(size, -1){}

    int root(int x){

        return t[x] < 0 ? x : t[x] = root(t[x]);

    }

    int size(int x){

        return -t[root(x)];

    }

    bool isSame(int x, int y){

        return root(x) == root(y);

    }

    bool unite(int x, int y){

        x = root(x), y = root(y);

        if(x != y){

            if(t[y] < t[x]){

                swap(x, y);

            }

            t[x] += t[y], t[y] = x;

        }

        return x != y;

    }

};

int n, m, x, y, h, w, res = 0, cnt = 0, sum = 0, mx = -INF, mn = INF;

string s, t;

main(){

    incant();

    in(n, x, y);

    int a[n], b[n], c[n], dp[n + 1][n * 10 + 1][n * 10 + 1]; //i番目まででjグラム、kグラムをませるときに必要な最小金額

    rep(i, n) in(a[i], b[i], c[i]);

    rep(i, n + 1) rep(j, n*10 + 1) rep(k, n*10 + 1) dp[i][j][k] = INF;

    dp[0][0][0] = 0;

    rep(i, n) rep(j, n*10 + 1) rep(k, n*10 + 1){

        if(dp[i][j][k] != INF) chmin(dp[i + 1][j][k], dp[i][j][k]), chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);

    }

    rep(i, 1, n*10 + 1) rep(j, 1, n*10 + 1) if(i*y == j*x) chmin(mn, dp[n][i][j]);

    out(mn < INF ? mn : -1);

}

// Fastest known solution for this problem: