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

const int INF = 1e9;
int n, ma, mb;

int chemA[40];
int chemB[40];
int chemC[40];

int dp[401][401];

int main() {
	cin >> n >> ma >> mb;
	for(int i = 0; i < n; i++) {
		cin >> chemA[i] >> chemB[i] >> chemC[i];
	}

	for(int i = 0; i < 401; i++) for(int j = 0; j < 401; j++) dp[i][j] = INF;

	dp[0][0] = 0;
	for(int k = 0; k < n; k++) {
		for(int i = 10*n; i >= 0; i--) {
			for(int j = 10*n; j >= 0; j--) {
				if(dp[i][j] == INF) continue;
				dp[i+chemA[k]][j+chemB[k]] = min(dp[i+chemA[k]][j+chemB[k]], dp[i][j] + chemC[k]);
			}
		}
	}

	int ans = INF;
	int fac = 1;
	while(fac*ma <= 10*n && fac*mb <= 10*n) {
		ans = min(ans, dp[fac*ma][fac*mb]);
		fac++;
	}
	cout << ((ans == INF)? -1:ans) << endl;

	return 0;
}