#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int dp[401][401];

int main() {
	int n, m1, m2; scanf("%d%d%d", &n, &m1, &m2);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	rep(i, n) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		int t = i * 10;
		for (int j = t; j >= 0; j--)for (int k = t; k >= 0; k--) {
			dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
		}
	}
	int Min = INF;
	for (int i = 1; i*m1 <= 400 && i*m2 <= 400; i++)
		Min = min(Min, dp[m1*i][m2*i]);
	if (Min == INF)puts("-1");
	else printf("%d\n", Min);
}