#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890
 
int main(){
    ll i,j,k;
    ll n,ma,mb;
    cin>>n>>ma>>mb;
    VVI dp(404,VI(404,INF));
    dp[0][0]=0;
    for(k=0;k<n;k++){
        ll a,b,c;
        cin>>a>>b>>c;
        for(i=403;i>=a;i--){
            for(j=403;j>=b;j--){
                dp[i][j]=min(dp[i][j],dp[i-a][j-b]+c);
            }
        }
    }
    ll ans=INF;
    for(i=1;i*max(ma,mb)<404;i++){
        ans=min(ans,dp[i*ma][i*mb]);
    }
    if(ans==INF) ans=-1;
    cout<<ans<<endl;

    return 0;
}