#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
static const int INF = 0x3f3f3f3f;
int dp[401][401];
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < 401; i ++) {
for (int j = 0; j < 401; j ++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; i ++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
for (int y = 400; y >= 0; y --) {
for (int x = 400; x >= 0; x --) {
if (dp[x][y] < INF) {
dp[x + a][y + b] = min(dp[x + a][y + b], dp[x][y] + c);
}
}
}
}
int res = INF;
for (int i = 0; i < 401; i ++) {
for (int j = 0; j < 401; j ++) {
if (dp[i][j] < res && i > 0) {
if (i * b == j * a) res = dp[i][j];
}
}
}
if (res == INF) res = -1;
printf("%d\n", res);
return 0;
}