#include <bits/stdc++.h>

// limit
#define mod1 22439423LL
#define mod2 42342432LL
#define mod3 56454765LL
#define mod4 66867574LL
#define oo 1000000007LL
#define OO 1000000000000000007LL
#define maxN 5007

// loop
#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define fdtoa(i, x, y, a) for(int i = (x); i >= (y); i -= a)
#define ftosqrt(i, x, y) for(int i = (x); i*i <= (y); ++i)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define fdtoit(rit, var) for (__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); ++rit)

// debug
#define debug cout << "*" << endl;
#define bug1d(a, x, y) { cout << #a << ": "; fto(_, x, y) cout << a[_] << ' '; cout << endl; }
#define bug2d(a, x, y, u, v) { cout << #a << ": " << endl; fto(i, x, y) {fto(j, u, v) cout << a[i][j] << ' '; cout << endl;}; cout << endl;}
#define bug(a) cout << #a << " = " << a << endl;
#define bug2(a, b) cout << #a << " = " << a << "; "; cout << #b << " = " << b << endl;
#define bug3(a, b, c) cout << #a << " = " << a << "; "; cout << #b << " = " << b << "; "; cout << #c << " = " << c << endl;

// operation
#define mp make_pair
#define pb push_back
#define pf push_front
#define mt make_tuple

// structure
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define matrix vector<vi>
#define iii pair <ii, int>

// get value
#define FF first
#define SS second
#define get(x, a) get<(x)>(a)

// data type
#define ll long long
#define ull unsigned long long

// function
#define lb lower_bound
#define ub upper_bound

// const value
#define pi 3.14159265358979323846264338327950288419716939937510

using namespace std;

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T min(T a, T b, T c, T d) {
    return min(a, min(b, min(c, d)));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

template <class T>
T max(T a, T b, T c, T d) {
    return max(a, max(b, max(c, d)));
}

bool cmp(const int& a, const int& b) {return a > b;}

int f1[maxN][maxN], f2[maxN][maxN];
int check[maxN][maxN], tmp[maxN][maxN];
int a[maxN], b[maxN], c[maxN];

int main() {
//    #ifndef ONLINE_JUDGE
//        freopen("tmp.inp", "r", stdin);
//        freopen("tmp.out", "w", stdout);
//    #endif // ONLINE_JUDGE

    int n, mA, mB;
    scanf("%d%d%d", &n, &mA, &mB);

    fto (i, 1, n) scanf("%d%d%d", &a[i], &b[i], &c[i]);

    check[0][0] = 1;
    fto (i, 0, 500) {
        fto (j, 0, 500) f2[i][j] = f1[i][j] = oo;
    }
    f2[0][0] = 0;
    f1[0][0] = 0;

    fto (i, 1, n) {
        fto (j, 0, 500) {
            fto (k, 0, 500) {
                if (check[j][k]) {
                    f2[j+a[i]][k+b[i]] = min(f2[j+a[i]][k+b[i]], f1[j][k]+c[i]);
                    tmp[j+a[i]][k+b[i]] = 1;
                }
            }
        }
        fto (j, 0, 500) {
            fto (k, 0, 500) {
                f1[j][k] = f2[j][k];
                check[j][k] |= tmp[j][k];
                tmp[j][k] = 0;
            }
        }
    }

//    fto (i, 0, 7) {
//        fto (j, 0, 7) if (f1[i][j] == oo) cout << "   oo"; else printf("%5d", f1[i][j]);
//        puts("");
//    }

    int ans = oo;
    fto (i, 0, 4000) {
        fto (j, 0, 4000) {
            if (i > 0 && j > 0 && i%mA == 0 && j%mB == 0 && i/mA == j/mB && check[i][j]) ans = min(ans, f1[i][j]);
        }
    }

    if (ans == oo) puts("-1");
    else printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 45952