#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)

	ll dp[41][405][405];
	
int main(){
	ll n,ma,mb;
	cin>>n>>ma>>mb;
	rep(i,0,n+1)rep(j,0,405)rep(k,0,405)dp[i][j][k]=inf;
	ll a[41],b[41],c[41];
	rep(i,0,n)cin>>a[i]>>b[i]>>c[i];
	dp[0][0][0]=0;
	rep(i,0,n)rep(j,0,405)rep(k,0,405){
		if(dp[i][j][k]==inf)continue;
		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]);
		dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
	}
	ll ans=inf;
	rep(i,1,405)rep(j,1,405)if(i*mb==j*ma)ans=min(ans,dp[n][i][j]);
	if(ans==inf)cout<<-1<<endl;
	else cout<<ans<<endl;
				
}