#include <iostream>

using namespace std ;

int a[40], b[40], c[40];
int n, ma, mb;

int main(void){
    cin>>n;
    cin>>ma;
    cin>>mb;
    for(int i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
        cin>>c[i];
    }
    int ans=search(0, 0, 0, 0);
    if(ans==10000) ans=-1;
    cout<<ans;
}

int search(int sumA, int sumB, int sumC, int st){
    if(st==n-1){
            if(sumA*mb==sumB*ma && sumA!=0) return sumC;
            else if((sumA+a[n-1])*mb==(sumB+b[n-1]*ma)) return sumC+c[n-1];
            else return 10000;
        }
        return min(search(sumA+a[st], sumB+b[st], sumC+c[st], st+1), search(sumA, sumB, sumC, st+1));
}