#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int num;
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

struct UnionFind_P {
private:
	vector<int> data;
	vector<ll> sz;
	int root(int x) {
		return data[x] < 0 ? x : root(data[x]);
	}

public:
	vector<vector<pii>> tb;
	vector < vector <pair<int, ll> >> tsz;
	int s_cou = 0;
	UnionFind_P(int size) : tb(size, vector<pii>(1)), data(size, -1), sz(size, 0), tsz(size, vector<pair<int,ll>>(1)) {
		REP(i, size) {
			tb[i][0] = { 0, i };
		}
	}

	void Initsz(vector<ll> szarr) {
		REP(i, data.size()) {
			sz[i] = szarr[i];
			tsz[i][0] = { 0,szarr[i] };
		}
	}

	//tを小さい順にやるならおｋだよ お祭りで使った
	//bool unionSet(int x, int y, int t) { //ｘの入ってる集合と yの入ってる集合を併合
	//	x = root(x); y = root(y);
	//	s_cou++;
	//	if (x != y) {
	//		if (data[y] < data[x]) swap(x, y);
	//		data[x] += data[y]; data[y] = x;
	//		if (tb[y][tb[y].size() - 1].first != t)
	//			tb[y].push_back({ t,x });
	//		else
	//			tb[y][tb[y].size() - 1].second = x;
	//	}
	//	return x != y;
	//}
	bool unionSet(int x, int y) { //ｘの入ってる集合と yの入ってる集合を併合
		x = root(x); y = root(y);
		s_cou++;
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			tb[y].push_back({ s_cou,x });

			sz[x] += sz[y];
			sz[y] = 0;
			tsz[x].push_back({s_cou, sz[x]});

		}
		return x != y;
	}
	int findroot(int u, int t) {
		auto itr = --upper_bound(ALL(tb[u]), MP(t, INT_MAX));
		return itr->second == u ? u : findroot(itr->second, t);
	}

	int getsz(int u, int t) {
		int rt = findroot(u, t);
		auto itr = --upper_bound(ALL(tsz[rt]), MP(t, LLONG_MAX));
		return itr->second;
	}

};

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
signed main(void) {
	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];
	}

	int dp[41][401][401] = {};
	Fill(dp, 99999999);

	dp[0][0][0] = 0;

	REP(i, n) {
		REP(j, 401) {
			REP(k, 401) {
				if (dp[i][j][k] != 99999999) {
					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 + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
				}
			}
		}
	}

	int Min = 99999999;

	rep(j,1, 401) {
		rep(k,1, 401) {
			if (dp[n][j][k] != 99999999) {
				int g = gcd(j, k);
				if (j / g == ma && k / g == mb) {
					Min = min(Min,dp[n][j][k]);
				}
			}
		}
	}

	if (Min == 99999999)
		cout << -1 << endl;
	else
	{
		cout << Min << endl;
	}
	return 0;
}



Measured memory_bytes: 25984