// Slower C++ solution:
#include <iostream>

#include <iomanip>

#include <cstdio>

#include <string>

#include <cstring>

#include <deque>

#include <list>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <algorithm>

#include <map>

#include <set>

#include <complex>

#include <cmath>

#include <limits>

#include <cfloat>

#include <climits>

#include <ctime>

#include <cassert>

using namespace std;



#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)

#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

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

#define pb(a) push_back(a)

#define fr first

#define sc second

#define INF 2000000000

#define int long long int



#define X real()

#define Y imag()

#define EPS (1e-10)

#define EQ(a,b) (abs((a) - (b)) < EPS)

#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )

#define LE(n, m) ((n) < (m) + EPS)

#define LEQ(n, m) ((n) <= (m) + EPS)

#define GE(n, m) ((n) + EPS > (m))

#define GEQ(n, m) ((n) + EPS >= (m))



typedef vector<int> VI;

typedef vector<VI> MAT;

typedef pair<int, int> pii;

typedef long long ll;



typedef complex<double> P;

typedef pair<P, P> L;

typedef pair<P, double> C;



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

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

int const MOD = 1000000007;



namespace std {

    bool operator<(const P& a, const P& b) {

        return a.X != b.X ? a.X < b.X : a.Y < b.Y;

    }

}



int n, ma, mb;

int dp[50][500][500];



signed main() {

    cin >> n >> ma >> mb;

    int a[50], b[50], c[50];

    rep(i,0,n) {

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

    }



    repq(i,0,n) rep(j,0,500) rep(k,0,500) dp[i][j][k] = INF;

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



    rep(i,0,n) rep(j,0,500) rep(k,0,500) {

        dp[i+1][j][k] = dp[i][j][k];

        if(j - a[i] < 0 || k - b[i] < 0) continue;

        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j-a[i]][k-b[i]] + c[i]);

    }



    int ans = INF;

    rep(i,1,500) rep(j,1,500) {

        if(ma * j == mb * i) {

            // printf("i = %lld, j = %lld, dp = %lld\n", i, j, dp[n][i][j]);

            ans = min(ans, dp[n][i][j]);

        }

    }

    if(ans != INF) cout << ans << endl;

    else cout << -1 << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9519975891416874x):
#include <iostream>

#include <iomanip>

#include <cstdio>

#include <string>

#include <cstring>

#include <deque>

#include <list>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <algorithm>

#include <map>

#include <set>

#include <complex>

#include <cmath>

#include <limits>

#include <cfloat>

#include <climits>

#include <ctime>

#include <cassert>

#include <numeric>

#include <functional>

using namespace std;



#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)

#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

#define int long long int



template<typename T> void chmax(T &a, T b) {a = max(a, b);}

template<typename T> void chmin(T &a, T b) {a = min(a, b);}

template<typename T> void chadd(T &a, T b) {a = a + b;}



typedef pair<int, int> pii;

typedef long long ll;



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

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

constexpr ll INF = 1001001001001001LL;

constexpr ll MOD = 1000000007LL;



// dp[i][j] := A の物質量が i、B の物質量が j の時のコスト最小

int dp[410][410];

int N, Ma, Mb, a[50], b[50], c[50];



signed main() {

    rep(i,0,410) rep(j,0,410) dp[i][j] = INF;

    dp[0][0] = 0;



    cin >> N >> Ma >> Mb;

    rep(i,0,N) cin >> a[i] >> b[i] >> c[i];



    int ans = INF;

    rep(i,0,N) repr(j,400,0) repr(k,400,0) {

        if(j-a[i] < 0 || k-b[i] < 0) continue;

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

        if(j != 0 && k != 0 && j*Mb == k*Ma) chmin(ans, dp[j][k]);

    }

    cout << (ans == INF ? -1 : ans) << endl;

    return 0;

}