using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using static MyBinarySearch;


public class MedicineSet : IComparable<MedicineSet>
{
	public int Rate { get; private set; } // sum(a) * Mb - sum(b) * Ma
	public int Cost { get; private set; }

	public MedicineSet(int rate, int cost)
	{
		Rate = rate;
		Cost = cost;
	}

	public int CompareTo(MedicineSet x)
	{
		return Rate - x.Rate;
	}
}


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int Ma = GetInt();
		int Mb = GetInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];
		for(int i = 0; i < N; i++)
		{
			a[i] = GetInt();
			b[i] = GetInt();
			c[i] = GetInt();
		}

		int size0 = (N + 1)/2;
		int size1 = N - size0;

		bool exist = false;
		int ans = int.MaxValue;

		List<MedicineSet> sets0 = new List<MedicineSet>(size0);
		for(int s = 1; s < (1 << size0); s++)
		{
			int rate = 0;
			int cost = 0;
			for(int i = 0; i < size0; i++)
			{
				if(((s >> i) & 1) == 0)
					continue;
				rate += a[i] * Mb - b[i] * Ma;
				cost += c[i];
			}
			sets0.Add(new MedicineSet(rate, cost));

			if(rate == 0)
			{
				exist = true;
				ans = Math.Min(ans, cost);
			}
		}

		List<MedicineSet> sets1 = new List<MedicineSet>(size1);
		for(int s = 1; s < (1 << size1); s++)
		{
			int rate = 0;
			int cost = 0;
			for(int i = 0; i < size1; i++)
			{
				if(((s >> i) & 1) == 0)
					continue;
				rate += a[i + size0] * Mb - b[i + size0] * Ma;
				cost += c[i + size0];
			}
			sets1.Add(new MedicineSet(rate, cost));

			if(rate == 0)
			{
				exist = true;
				ans = Math.Min(ans, cost);
			}
		}
		sets1.Sort(
			(x,y) => (x.Rate - y.Rate) != 0 ?
				(x.Rate - y.Rate) : (x.Cost - y.Cost));

		
		foreach(MedicineSet set0 in sets0)
		{
			int index = sets1.LowerBound(new MedicineSet(-set0.Rate, -1));
			if((index < 0) || (index >= sets1.Count))
				continue;
			if(sets1[index].Rate != -set0.Rate)
				continue;
			
			exist = true;
			ans = Math.Min(ans, set0.Cost + sets1[index].Cost);
		}
		Console.WriteLine(exist ? ans : -1);
	}
}


public static class MyBinarySearch
{
	public static int LowerBound<T>(
		this List<T> list, int first, int end, T value, IComparer<T> comparer)
	{
		int low = first;
		int high = end;
		while(low < high)
		{
			int mid = ((high - low) >> 1) + low;
			if(comparer.Compare(list[mid], value) < 0)
				low = mid + 1;
			else
				high = mid;
		}
		return low;
	}

	public static int LowerBound<T>(this List<T> list, T value)
	{
		return list.LowerBound(0, list.Count, value, Comparer<T>.Default);
	}

	public static int UpperBound<T>(
		this List<T> list, int first, int end, T value, IComparer<T> comparer)
	{
		int low = first;
		int high = end;
		while(low < high)
		{
			int mid = ((high - low) >> 1) + low;
			if(comparer.Compare(list[mid], value) <= 0)
				low = mid + 1;
			else
				high = mid;
		}
		return low;
	}

	public static int UpperBound<T>(this List<T> list, T value)
	{
		return list.UpperBound(0, list.Count, value, Comparer<T>.Default);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 89940