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

const int DIM = 4e2 + 5;

int dp[DIM][DIM];

int main( void ) {
    
    int n, a, b;
    cin >> n >> a >> b;
    
    memset( dp, 0x3f, sizeof(dp) );
    
    dp[0][0] = 0;
    for( int i = 1; i <= n; i ++ ) {
        int x, y, z;
        cin >> x >> y >> z;
        
        for( int j = DIM - 1; j >= x; j -- )
            for( int k = DIM - 1; k >= y; k -- )
                dp[j][k] = min( dp[j][k], dp[j - x][k - y] + z );
    }
    
    int ans = 1e9;
    for( int i = 1; max( a, b ) * i < DIM; i ++ )
        ans = min( ans, dp[i * a][i * b] );
    
    cout << ( ( ans == 1e9 ) ? -1 : ans ) << endl;
    return 0;
}