#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;

int Ma,Mb;

vector<int> A,B,C;

int main(){
  cin >> N >> Ma >> Mb;
  A.resize(N);
  B.resize(N);
  C.resize(N);
  rep(i,0,N - 1){
    cin >> A[i] >> B[i] >> C[i];
  }

  vector<vector<int>> dp(505,vector<int>(505,1e9));
  dp[0][0] = 0;

  rep(i,0,N - 1){
    auto next = dp;
    rep(a,0,400)rep(b,0,400){
      if(a - A[i] >= 0 && b - B[i] >= 0){
        next[a][b] = min(next[a][b],dp[a - A[i]][b - B[i]] + C[i]);
      }
    }
    swap(next,dp);
  }
  int a = Ma;
  int b = Mb;
  int ans = 1e9;
  while(a <= 400 && b <= 400){
    ans = min(ans , dp[a][b]);
    a += Ma;
    b += Mb;
  }

  cout << (ans == 1e9 ? -1 : ans) << endl;
}