import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class A{
	int a;
	int b;
	int c;
	int p;
 	this(int a, int b, int c){
		this.a = a, this.b = b, this.c = c;
		this.p = ma * b - mb * a;
		}
	}

int n, ma, mb;

// 問題はsum(p) = 0 となるときのsum(c)の最小値

void main(){
	{
		int[] tmp = readln.chomp.split.map!(to!int).array;
		n = tmp[0], ma = tmp[1], mb = tmp[2];
		}
	
	A[] as;
	for(int i = 0; i < n; i ++){
		int[] tmp = readln.chomp.split.map!(to!int).array;
		as ~= new A(tmp[0], tmp[1], tmp[2]);
		}
	
	int[int] dic1, dic2;
	int n2 = 0;
	if(n > 6){
		n2 = n / 2;
		{
			int i = n2 - 1;
			long m = 2 ^^ i;
			int sump = 0;
			int sumc = 0;
			long k = 0;
			while(1){
				if(sumc > 0){
					if(sump in dic1){
						if(sumc < dic1[sump]) dic1[sump] = sumc;
						}
					else dic1[sump] = sumc;
					}
				while(k & m){
					k -= m;
					sump -= as[i].p;
					sumc -= as[i].c;
					i -= 1, m /= 2;
					}
				if(m > 0){
					k += m;
					sump += as[i].p;
					sumc += as[i].c;
					i = n2 - 1, m = 2 ^^ i;
					}
				else break;
				}
			}
		}
	/*anyway*/
	{
		int i = n - n2 - 1;
		long m = 2 ^^ i;
		int sump = 0;
		int sumc = 0;
		long k = 0;
		while(1){
			if(sumc > 0){
				if(sump in dic2){
					if(sumc < dic2[sump]) dic2[sump] = sumc;
					}
				else dic2[sump] = sumc;
				}
			while(k & m){
				k -= m;
				sump -= as[i + n2].p;
				sumc -= as[i + n2].c;
				i -= 1, m /= 2;
				}
			if(m > 0){
				k += m;
				sump += as[i + n2].p;
				sumc += as[i + n2].c;
				i = n - n2 - 1, m = 2 ^^ i;
				}
			else break;
			}
		}
	
	debug dic1.writeln;
	debug dic2.writeln;
	
	int minsumc = int.max;
	if(0 in dic1) minsumc = min(minsumc, dic1[0]);
	if(0 in dic2) minsumc = min(minsumc, dic2[0]);
	foreach(sp; dic1.keys){
		if(-sp in dic2){
			int s = dic1[sp] + dic2[-sp];
			if(s < minsumc && s > 0) minsumc = s;
			}
		}
	
	int ans;
	if(minsumc == int.max) ans = -1;
	else ans = minsumc;
	
	ans.writeln;
	}