#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 50;
const int INF = 0x3f3f3f3f;
int dp[4010][4010];
int a[maxn], b[maxn], c[maxn];
int n, m1, m2;
int v1, v2;


int main(){
	memset(dp, INF, sizeof(dp));
	dp[0][0] = 0;
	cin >> n >> m1 >> m2;
	for (int i = 1; i <= n; ++i){
		cin >> a[i] >> b[i] >> c[i];
		v1 += a[i];
		v2 += b[i];
	}
	for (int i = 1; i <= n;++i)
	for (int j = v1; j >= a[i];--j)
	for (int k = v2; k >= b[i]; --k)
		dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]]+c[i]);
	int kk = INF;
	for (int i = 1; i*m1 <= v1&&i*m2 <= v2; ++i){
		kk = kk < dp[i*m1][i*m2] ? kk : dp[i*m1][i*m2];
	}
	if (kk == INF)cout << -1 << endl;
	else cout << kk << endl;
}