#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


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

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

int N;
int Ma, Mb;
vector<int> a;
vector<int> b;
vector<int> c;

vector<int> d;
vector<int> e;
vector<int> f;


struct state{
    
    double A, B, C;
    
};

struct Compare{
    bool operator()(const state& lhs, const state & rhs) {
        return lhs.A * Ma - lhs.B * Mb < rhs.A * Ma - rhs.B * Mb;
    }
};

int main() {

    cin >> N >> Ma >> Mb;
    int half = N/2;
    int rest = N-half;
    a.resize(half);b.resize(half);c.resize(half);
    d.resize(rest);e.resize(rest);f.resize(rest);

    
    for(auto i = 0; i<half; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(auto i = 0; i<rest; i++){
        cin >> d[i] >> e[i] >> f[i];
    }
    
    map<pii,int> pre, after;
    
    for(auto i = 0; i< (1<<half); i++){
        
        auto temp = i;
        int count = 0;
        pii p = make_pair(0,0);
        int sum = 0;
        while(temp != 0){
            if(temp%2 == 1){
                p.first += a[count];
                p.second += b[count];
                sum += c[count];
            }
            temp/=2;
            count++;
        }
        if(pre.count(p)) pre[p] = min(pre[p],sum);
        else pre[p]  =sum;
    }
    
    for(auto i = 0; i< (1<<rest); i++){
        
        auto temp = i;
        int count = 0;
        pii p = make_pair(0,0);
        int sum = 0;
        while(temp != 0){
            if(temp%2 == 1){
                p.first += d[count];
                p.second += e[count];
                sum += f[count];
            }
            temp/=2;
            count++;
        }
        if(after.count(p)) after[p] = min(after[p],sum);
        else after[p]  =sum;
    }
    
    
    int ans = INF;
    
    for(auto it:after){
        
        repsg(j,1,405){
            pii p = make_pair( Ma * j - it.first.first, Mb * j - it.first.second );
            
            if(pre.count(p)) ans = min(ans, pre[p] + it.second);
            
        }
        
        
    }
    
    
    
    
    if (ans != INF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    
    return 0;
}









Measured memory_bytes: 896