#include<bits/stdc++.h>
using namespace std;
int memo[1001][1001]={},ma,mb;
int a[40],b[40],c[40];
void sai(int n,int mx,int aa,int bb){
  if(n>=mx){
    return ;
  }
  for(int i=n+1;i<mx;i++){
    int na=aa+a[i],nb=bb+b[i];
    while(na-ma>=0&&nb-mb>=0&&!(na==ma&&nb==mb)){
      na-=ma;
      nb-=mb;
    }
    if(memo[na][nb]==0||memo[na][nb]>memo[aa][bb]+c[i]){
      memo[na][nb]=memo[aa][bb]+c[i];
      sai(i,mx,na,nb);
    }
  }
  return;
}
int main(){
  int n;
  cin>>n>>ma>>mb;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  sai(-1,n,0,0);
  if(memo[ma][mb]!=0){
    cout<<memo[ma][mb]<<endl;
  }else{
    cout<<"-1"<<endl;
  }
  return(0);
}