#include <iostream>
#define INF 1000000
using namespace std;
int main(void){
    int n, ma, mb, ans, dp[2][401][401];;
    cin >> n >> ma >> mb;
    for(int j=0;j<=400;j++){
        for(int k=0;k<=400;k++){
            dp[0][j][k] = INF;
        }
    }
    dp[0][0][0] = 0;
    for(int i=1;i<=n;i++){
        int a, b, c;
        cin >> a >> b >> c;
        for(int j=0;j<=400;j++){
            for(int k=0;k<=400;k++){
                dp[i%2][j][k] = dp[1-i%2][j][k];
                if(j >= a && k >= b){
                    dp[i%2][j][k] = min(dp[i%2][j][k], dp[1-i%2][j-a][k-b] + c);
                }
            }
        }
    }
    ans = INF;
    for(int i=1;ma*i<=400&&mb*i<=400;i++){
        ans = min(ans, dp[n%2][ma*i][mb*i]);
    }
    if(ans >= INF)ans = -1;
    cout << ans << endl;
    
}
