#include <iostream>
using namespace std;

int main(){
    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    int dp[N+1][N*10+1][N*10+1];
    fill(dp[0][0],dp[N+1][0],1000000000);
    dp[0][0][0]=0;
    for(int i=0;i<N;i++){
        int a,b,c;
        cin>>a>>b>>c;
        for(int aa=0;aa<=i*10;aa++){
            for(int bb=0;bb<=i*10;bb++){
                dp[i+1][aa][bb]=dp[i][aa][bb];
            }
        }
        for(int aa=0;aa<=i*10;aa++){
            for(int bb=0;bb<=i*10;bb++){
                dp[i+1][aa+a][bb+b]=min(dp[i+1][aa+a][bb+b],dp[i][aa][bb]+c);
            }
        }
    }
    int ans=1000000000;
    for(int k=1;k*Ma<=N*10&&k*Mb<=N*10;k++){
        ans=min(ans,dp[N][k*Ma][k*Mb]);
    }
    if(ans==1000000000)ans=-1;
    cout<<ans<<endl;
    return 0;
}