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

#include<vector>

#include<algorithm>

#include<cctype>

#include<utility>

#include<string>

#include<cmath>

#include <numeric>

#include<queue>

#include<climits>





#define REP(i, n) for(int i = 0;i < n;i++)

#define REPR(i, n) for(int i = n;i >= 0;i--)

#define FOR(i, m, n) for(int i = m;i < n;i++)

#define FORR(i, m, n) for(int i = m;i >= n;i--)

#define SORT(v, n) sort(v, v+n);

#define VSORT(v) sort(v.begin(), v.end());

#define llong long long

#define pb(a) push_back(a)

//#define INF LLONG_MAX / 2;

using namespace std;

typedef pair<int, int> P;

typedef pair<llong, llong> LP;

typedef pair<int, P> PP;

typedef pair<llong, LP> LPP;

typedef long long int ll;

typedef pair<ll,int> LL_IP;



const ll INF = LLONG_MAX;



#define ARRAY_MAX 100005

#define N_MAX 45

#define AB_MAX 15

#define INF 1e9



int dp[N_MAX][N_MAX * AB_MAX][N_MAX * AB_MAX];



int main(){



    int n,ma,mb;

    cin >> n >> ma >> mb;

    vector<int> a(n),b(n),c(n);

    REP(i,n){

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

    }



    for(int i = 0;i <= n;i++){

        for(int j = 0;j <= N_MAX*AB_MAX;j++){

            for(int k = 0;k <= N_MAX*AB_MAX;k++){

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

            }

        }

    }





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

    

    for(int i = 1;i <= n;i++){

        for(int j = 0;j <= N_MAX*AB_MAX;j++){

            for(int k = 0;k <= N_MAX*AB_MAX;k++){

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

                    continue;

                }

                dp[i][j][k] = min(dp[i][j][k],dp[i-1][j][k]);

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

            }

        }

    }

    int ans = INF;



    for(int i = 1;i <= N_MAX*AB_MAX;i++){

        for(int j = 1;j <= N_MAX*AB_MAX;j++){

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

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

            }

        }

    }



    if(ans == INF){

        ans = -1;

    }

    cout << ans << endl;









    return 0;

}

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

#include<vector>

#include<algorithm>

#include<cctype>

#include<utility>

#include<string>

#include<cmath>

#include<cstring>

#include<queue>

#include<map>

#include<set>

#include<climits>

#include<bitset>

#include<stack>



#define REP(i, n) for(int i = 0;i < n;i++)

#define REPR(i, n) for(int i = n;i >= 0;i--)

#define FOR(i, m, n) for(int i = m;i < n;i++)

#define FORR(i, m, n) for(int i = m;i >= n;i--)

#define SORT(v, n) sort(v, v+n);

#define VSORT(v) sort(v.begin(), v.end());

#define llong long long

#define pb(a) push_back(a)

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)



using namespace std;



typedef long long int ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef tuple<ll, ll, ll, ll> lltpl;



int dy[8] = { 2,2,-2,-2,1,1,-1,-1 };

int dx[8] = { 1,-1,1,-1,2,-2,2,-2 };







/******************************************************************************************/





const int IINF = 1e9 + 7;

const ll LINF = 1e18 + 7;

const ll MOD = 998244353;







template<typename T>

vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>

auto make_v(size_t a, Ts... ts) {

	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));

}

template<typename T, typename V>

typename enable_if<is_class<T>::value == 0>::type

fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>

typename enable_if<is_class<T>::value != 0>::type

fill_v(T& t, const V& v) {

	for (auto& e : t) fill_v(e, v);

}



// vector

template <typename T>

istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }

// pair

template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }

// vector

template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }

// map

template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }

// set

template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }







int dp[410][410];



int main() {



	cin.tie(nullptr);

	ios::sync_with_stdio(false);



	int N, Ma, Mb;

	cin >> N >> Ma >> Mb;



	vector<int> a(N), b(N), c(N);



	for (int i = 0; i < 410; i++)

	{

		for (int j = 0; j < 410; j++)

		{

			dp[i][j] = IINF;

		}

	}



	for (int i = 0; i < N; i++)

	{

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

	}

	dp[0][0] = 0;

	for (int i = 0; i < N; i++)

	{

		for (int j = 400; j >= 0; j--)

		{

			for (int k = 400; k >= 0; k--)

			{

				if (j + a[i] <= 405 && k + b[i] <= 405) {

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

				}

			}

		}

	}



	int mini = IINF;



	for (int i = 1; i <= 400; i++)

	{

		for (int j = 1; j <= 400; j++)

		{

			if (i * Mb == j * Ma) {



				mini = min(mini, dp[i][j]);

			}

		}

	}



	if (mini == IINF) {

		cout << "-1" << endl;

	}

	else

	{

		cout << mini << endl;

	}











}