#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int dp[45][500][500];
int main(){
    int n, a, b;
    int x, y, z;
    scanf("%d%d%d",&n,&a,&b);
    memset(dp,0x7f,sizeof(dp));
    dp[0][0][0] = 0;
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&x,&y,&z);
        for(int j=0;j<=400;j++)
        for(int k=0;k<=400;k++){
            if(dp[i-1][j][k] != 0x7f7f7f7f){
                dp[i][j][k] = min(dp[i-1][j][k],dp[i][j][k]);
                dp[i][j+x][k+y] = min(dp[i][j+x][k+y],dp[i-1][j][k] + z);

            }
        }
    }

    int ans = 0x7f7f7f7f;
    for(int i=a,j=b;i<=400&&j<=400;i+=a,j+=b){
            ans = min(ans,dp[n][i][j]);
    }
    printf("%d\n",ans!=0x7f7f7f7f?ans:-1);
    return 0;
}
