#include <bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, Ma, Mb;
  int dp[401][401];
  fill_n(*dp, 401 * 401, INF);

  cin >> N >> Ma >> Mb;
  dp[0][0] = 0;
  for(int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    for(int j = 400; j >= a; j--) {
      for(int k = 400; k >= b; k--) {
        dp[j][k] = min(dp[j][k], dp[j - a][k - b] + c);
      }
    }
  }

  int ret = INF;
  for(int i = 1; i < 401; i++) {
    for(int j = 1; j < 401; j++) {
      // i : j = Ma : Mb
      if(i * Mb == j * Ma) ret = min(ret, dp[i][j]);
    }
  }

  if(ret == INF) ret = -1;
  cout << ret << endl;
}