import std.algorithm;
import std.stdio;
import std.typecons;

immutable int maxL = 401;
immutable int inf = int.max / 2;

void main ()
{
	int n;
	int ma, mb;
	while (readf (" %s %s %s", &n, &ma, &mb) > 0)
	{
		alias Substance = Tuple !(int, q{a}, int, q{b}, int, q{c});
		int [maxL] [maxL] f;
		foreach (ref line; f)
		{
			line[] = inf;
		}
		f[0][0] = 0;
		foreach (i; 0..n)
		{
			Substance cur;
			readf (" %s %s %s", &cur.a, &cur.b, &cur.c);
			foreach (p; cur.a..maxL)
			{
				foreach (q; cur.b..maxL)
				{
					f[p][q] = min (f[p][q],
					    f[p - cur.a][q - cur.b] + cur.c);
				}
			}
		}

		int res = inf;
		foreach (p; 1..maxL)
		{
			foreach (q; 1..maxL)
			{
				if (p * mb == q * ma)
				{
					res = min (res, f[p][q]);
				}
			}
		}
		if (res >= inf)
		{
			res = -1;
		}
		writeln (res);
	}
}
