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

#include<vector>

#include<algorithm>

#include<cctype>

#include<utility>

#include<string>

#include<cmath>

#include<cstring>

#include<queue>

#include<map>

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

using namespace std;

typedef pair<int, int> P;

typedef long long int ll;

typedef pair<ll,ll> LLP;

#define INF 1000000007



#define ARRAY_MAX 15





//半分全列挙

void build(int first,int last,vector<int>& a,vector<int>& b,vector<int>& c,map<P,int>& mp){



    int times = last - first;

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



        int suma = 0,sumb = 0,cost = 0;

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

            

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

                //選ぶ

                suma += a[first + j];

                sumb += b[first + j];

                cost += c[first + j];

            }

        }

        if(!mp.count({suma, sumb}) || mp[{suma, sumb}] > cost) {

            mp[{suma, sumb}] = cost;

        }

    }

}









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

    }



    map<P,int> s1,s2;



    build(0,n/2,a,b,c,s1);//前半部分

    build(n/2,n,a,b,c,s2);//後半部分

    int ans = INF;



    for(auto itr1:s1){

        for(auto itr2:s2){

            int a1 = itr1.first.first + itr2.first.first;//aの重さ

            int b1 = itr1.first.second + itr2.first.second;//bの重さ

            if(a1 * b1 > 0 && a1*mb == b1*ma){

                ans = min(ans,itr1.second + itr2.second);

            }

        }

    }

    if(ans == INF){

        cout << "-1" << endl;

    }else{

        cout << ans << endl;

    }





    return 0;

}