#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)

const int INF = 114514810;
int n, ma, mb;
vector<int> a, b, c;

int dp[44][444][444];

int rec(int i, int wa, int wb) {
    int &r = dp[i][wa][wb];
    if (r < INF) return r;
    if (i == n) {
        if (wa * mb != wb * ma || wa == 0 || wb == 0) return r = INF - 1;
        return r = 0;
    }
    return r = min(rec(i + 1, wa + a[i], wb + b[i]) + c[i], rec(i + 1, wa, wb));
}

int main() {
    cin >> n >> ma >> mb;
    a.resize(n); b.resize(n); c.resize(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    rep(i, 44) rep(j, 444) rep(k, 444) dp[i][j][k] = INF;
    int ans = rec(0, 0, 0);
    cout << (ans == INF - 1 ? -1 : ans) << endl;

    return 0;
}