#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,Ma,Mb;
    cin >> N >> Ma >> Mb;
    vi A(N),B(N),C(N);
    rep(i,N) cin >> A[i] >> B[i] >> C[i];
    
    ve<pair<pii,int>> S1,S2;
    
    for (int i = 0; i < (1 << N/2); i++) {
        int sa = 0,sb = 0,sc = 0;
        rep(j,N/2){
            if(i & (1 << j)){
                sa += A[j];
                sb += B[j];
                sc += C[j];
            }
        }
        
        S1.pb({{sa,sb},sc});
    }
    
    for (int i = 0; i < (1 << (N-N/2)); i++) {
        int sa = 0,sb = 0,sc = 0;
        rep(j,N-N/2){
            if(i & (1 << j)){
                sa += A[N/2+j];
                sb += B[N/2+j];
                sc += C[N/2+j];
            }
        }
        
        S2.pb({{sa,sb},sc});
    }
    
    sort(all(S1));
    sort(all(S2));
    
    int ans = infi;

    
    rep(i,int(S1.size())){
        
        
        pair<pii,int> s;
        s.fi.fi = S1[i].fi.fi, s.fi.se = S1[i].fi.se, s.se = S1[i].se;
        
        if(s.se >= ans) continue;
        
        int ma = Ma, mb = Mb;
        int an = infi;
        while (ma <= 400 && mb <= 400) {
            
            if(ma < s.fi.fi || mb < s.fi.se){
                ma += Ma,mb += Mb;
                continue;
            }
            int mma = ma - s.fi.fi;
            int mmb = mb - s.fi.se;
            pair<pii,int> cc = {{mma,mmb},0};
            
            auto itr = lower_bound(all(S2),cc);
            if(itr == S2.end()) break;
            pair<pii,int> aaa = *itr;
            if(aaa.fi == cc.fi){
                chmin(an,aaa.se + s.se);
            }
            
            
            
            ma += Ma,mb += Mb;
        }
        
        chmin(ans,an);
        
        
        
    }
    
    if(ans == infi) cout << -1 << endl;
    else cout << ans << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 32744