#include "bits/stdc++.h"
using namespace std;
using     ll=long long;
using    vll=vector<   ll>;
using   vvll=vector<  vll>;
using  vvvll=vector< vvll>;
using vvvvll=vector<vvvll>;
constexpr ll INF = 1LL << 60;
struct Fast{ //cin,cout高速化のおまじない＋桁数指定
	Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits<double>::max_digits10); }
} fast;
#define rep(i, S, E)  for (ll i = (S); i <= (E); i++)
#define dep(i, E, S)  for (ll i = (E); i >= (S); i--)
#define each(e, v) for (auto&& e : v)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
template<class T> inline T POW(T a, ll n){ T r=1; for (; n>0; n>>=1, a*=a){ if (n&1)r*=a; } return r; }
inline ll POW(int a, ll n){ return POW((ll)a, n); }
inline ll CEIL(ll a, ll b){ return (a+b-1)/b; }

//tuple3用テンプレート
using   tll=tuple<ll,ll,ll>;
using  vtll=vector< tll>;
using vvtll=vector<vtll>;
template<class T,class S,class R> inline tuple<T,S,R>& operator+=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)+=get<0>(b); get<1>(a)+=get<1>(b); get<2>(a)+=get<2>(b); return a; }
template<class T,class S,class R> inline tuple<T,S,R>& operator-=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)-=get<0>(b); get<1>(a)-=get<1>(b); get<2>(a)-=get<2>(b); return a; }
template<class T,class S,class R> inline tuple<T,S,R>& operator*=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)*=get<0>(b); get<1>(a)*=get<1>(b); get<2>(a)*=get<2>(b); return a; }
template<class T,class S,class R> inline tuple<T,S,R>& operator/=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)/=get<0>(b); get<1>(a)/=get<1>(b); get<2>(a)/=get<2>(b); return a; }
template<class T,class S,class R> inline tuple<T,S,R>& operator%=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)%=get<0>(b); get<1>(a)%=get<1>(b); get<2>(a)%=get<2>(b); return a; }
template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator+=(tuple<T,S,R> &a,Q b){ get<0>(a)+=b; get<1>(a)+=b; get<2>(a)+=b; return a; }
template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator-=(tuple<T,S,R> &a,Q b){ get<0>(a)-=b; get<1>(a)-=b; get<2>(a)-=b; return a; }
template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator*=(tuple<T,S,R> &a,Q b){ get<0>(a)*=b; get<1>(a)*=b; get<2>(a)*=b; return a; }
template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator/=(tuple<T,S,R> &a,Q b){ get<0>(a)/=b; get<1>(a)/=b; get<2>(a)/=b; return a; }
template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator%=(tuple<T,S,R> &a,Q b){ get<0>(a)%=b; get<1>(a)%=b; get<2>(a)%=b; return a; }
template<class T,class S,class R,class Q> inline tuple<T,S,R> operator+(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c+=b; }
template<class T,class S,class R,class Q> inline tuple<T,S,R> operator-(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c-=b; }
template<class T,class S,class R,class Q> inline tuple<T,S,R> operator*(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c*=b; }
template<class T,class S,class R,class Q> inline tuple<T,S,R> operator/(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c/=b; }
template<class T,class S,class R,class Q> inline tuple<T,S,R> operator%(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c%=b; }
template<class T,class S,class R,class Q> inline tuple<T,S,R> operator-(Q b,const tuple<T,S,R> &a){ tuple<T,S,R> c=-a; return c+=b; }
template<class T,class S,class R> inline tuple<T,S,R> operator-(const tuple<T,S,R> &a){ tuple<T,S,R> c=a; return c*=(-1); }
template<class T,class S,class R> inline ostream &operator<<(ostream &os,const tuple<T,S,R> &a){ return os << get<0>(a) << ' ' << get<1>(a) << ' ' << get<2>(a); }


void solve()
{
	ll n,ma,mb;  cin >> n >> ma >> mb;
	vector<tuple<ll,ll,ll>> abc(n);
	rep(i,0,n-1){ ll a; ll b; ll c; cin>>a>>b>>c; abc[i]={a,b,c}; }


	ll mm=n/2;
	ll m=n-mm;

	map<ll,ll> mp;

	ll ans=INF;
	rep(s,1,(1LL<<mm)-1){
		tll sm{0,0,0};
		rep(i,0,mm-1){
			if (!(s&(1LL<<i)))continue;

			ll ii = i+m;
			sm+=abc[ii];
		}

		ll a,b,c;  tie(a,b,c) = sm;
		ll v=ma*b-mb*a;
		if (v==0){
			chmin(ans,c);
			continue;
		}
		if (mp.count(v)==0 or c<mp[v]){
			mp[v]=c;
		}
	}

	rep(s,1,(1LL<<m)-1){
		tll sm{0,0,0};
		rep(i,0,m-1){
			if (!(s&(1LL<<i)))continue;

			sm+=abc[i];
		}

		ll a,b,c;  tie(a,b,c) = sm;
		ll v=ma*b-mb*a;
		if (v==0){
			chmin(ans,c);
			continue;
		}

		if (mp.count(-v)==1){
			ll c2=mp[-v];
			chmin(ans,c+c2);
		}
	}
	if (ans==INF) ans=-1;
	cout << ans << '\n';
}


int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 3644