// 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 = 0;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][j][k] == INF){

                    continue;

                }

                //dp[i+1][j][k] = dp[i][j][k];

                //dp[i+1][j+a[i]][k+b[i]] = dp[i][j][k]+c[i];

                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);

                dp[i+1][j+a[i]][k+b[i]] = min(dp[i][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);

            }

        }

    }

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

#include<vector>

#include<algorithm>

#include<utility>

#include<string>

#include<cmath>

#include<cstring>

#include<queue>

#include<map>

#include<climits>

#include<queue>



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

int dx[4] = {1,0,0,-1};

int dy[4] = {0,1,-1,0};

#define INF 1000000007

#define MOD 1000000007

#define ARRAY_MAX 105







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 suma = itr1.first.first + itr2.first.first;

            int sumb = itr1.first.second + itr2.first.second;

            if(suma*sumb > 0 && suma*mb == sumb*ma){

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

            }

        }

    }

    if(ans == INF){

        cout << "-1" << endl;

    }else{

        cout << ans << endl;

    }





    return 0;

}