#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, Ma, Mb, a[41], b[41], c[41], memo[41][412][412];

int dp(int n, int aa, int bb)
{
	if (aa > 0 && bb > 0 && aa*Mb / Ma == bb && bb*Ma / Mb == aa) return 0;
	if (n == N) return 114514;
	if (memo[n][aa][bb] != -1) return memo[n][aa][bb];
	int res1 = dp(n + 1, aa + a[n], bb + b[n]) + c[n];
	int res2 = dp(n + 1, aa, bb);
	return memo[n][aa][bb] = std::min(res1, res2);
}

int main()
{
	in >> N >> Ma >> Mb;
	rep(i, N) in >> a[i] >> b[i] >> c[i];
	memset(memo, -1, sizeof(memo));
	out << (dp(0, 0, 0) >= 114514 ? -1 : dp(0, 0, 0)) << std::endl;
	return 0;
}
