// 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: 5.355561676458307x):
#include<iostream>

#include<vector>

#include<algorithm>

#include<cctype>

#include<utility>

#include<string>

#include<cmath>

#include<cstring>

#include<queue>

#include<map>

#include<set>

using namespace std;



#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 VSORT(v) sort(v.begin(), v.end());

#define pb(a) push_back(a)





typedef long long ll;



typedef pair<int, int> pii;

typedef pair<ll, ll> pll;



const int INF = 1e9 + 7;



#define ARRAY_MAX 100005



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);

}





int n, ma, mb;



struct goods {



	int a;

	int b;

	int c;



};





void build(int bg, int en, vector<goods>& t, map<pii,int>& ans) {



	int m = en - bg;

	for (int i = 0; i < (1 << m); i++) {

		int aa = 0, bb = 0, cc = 0;



		for (int j = 0; j < m; j++) {

			if ((i >> j) & 1) {

				aa += t[bg + j].a;

				bb += t[bg + j].b;

				cc += t[bg + j].c;

			}

		}

		if (ans.count({ aa,bb }) == 0 || ans[{aa,bb}] > cc)

		{

			ans[{aa, bb}] = cc;

		}

	}

}



int main() {



	

	cin >> n >> ma >> mb;





	vector<goods> vec(n);

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

	{

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

	}



	map<pii,int> ans1, ans2;



	build(0, n / 2, vec, ans1);

	build(n / 2, n, vec, ans2);



	int mini = INF;



	for (auto itr: ans1)

	{

		for (auto itr2 : ans2)

		{

			int aa = itr.first.first + itr2.first.first;

			int bb = itr.first.second + itr2.first.second;

			

			if (aa * mb == bb * ma && itr.second + itr2.second != 0)

			{

				mini = min(mini, itr.second + itr2.second);

			}

		}

	}

	if (mini == INF)

	{

		cout << "-1" << endl;

	}

	else

	{

		cout << mini << endl;

	}



	return 0;

}