#include <bits/stdc++.h>
using namespace std;


int memo[50][500][500];

int n, ma, mb;
int a[50], b[50], c[50];


int dfs(int i, int l, int r){
  if(l % ma == 0 && l != 0){
    int tmp = l / ma;
    if(tmp * mb == r) return 0;
  }

  if(i == n) return 100000;

  if(memo[i][l][r] != -1) return memo[i][l][r];

  return memo[i][l][r] = min(dfs(i+1,l,r), dfs(i+1,l+a[i],r+b[i]) + c[i]);
}

int main(){

  cin >> n >> ma >> mb;

  for(int i = 0;i < n;i++){
    cin >> a[i] >> b[i] >> c[i];
  }

  for(int i = 0;i < 50;i++){
    for(int j = 0;j < 500;j++){
      for(int k = 0;k < 500;k++){
        memo[i][j][k] = -1;
      }
    }
  }

  int ans;
  ans = dfs(0,0,0);
  if(ans >= 100000){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}