using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Comfort;
using static AtCoderer.Math;
using static AtCoderer.Algorithm;
using static System.Math;

namespace AtCoderer
{
    public class App
    {
        public static void Main(string[] args)
        { 
            Solve();
            Console.ReadKey();
        }
        public static void Solve()
        {
            int n, ma, mb;
            ParseArray(out n, out ma, out mb);
            int[,,] dp = new int[450, 450, 50];
            for (int i = 0; i < 400; i++)
            {
                for (int j = 0; j < 400; j++)
                {
                    for (int k = 0; k < 50; k++)
                    {
                        dp[i, j, k] = 231031015;
                    }
                }
            }
            dp[0, 0, 0] = 0;
            for (int k = 0; k < n; k++)
            {
                int a, b, c;
                ParseArray(out a, out b, out c);
                for (int i = 0; i < 400; i++)
                {
                    for (int j = 0; j < 400; j++)
                    {
                        if (i + a < 400 && j + b < 400)
                            dp[i + a, j + b, k + 1] = Min(dp[i + a, j + b, k + 1],dp[i, j, k] + c);
                        dp[i, j, k + 1] = Min(dp[i, j, k + 1],dp[i, j, k]);
                    }
                }
            }
            int f = int.MaxValue;
            for (int k = 0; k <= n; k++)
            {
                for (int i = 0; i < 400; i++)
                {
                    for (int j = 0; j < 400; j++)
                    {
                        if (i * mb == j * ma && (i != 0 || j != 0))
                        {
                            f = Min(f, dp[i, j, k]);
                        }
                    }
                }
            }
            Console.WriteLine(f > 231031014 ? -1 : f);
        }
        public static int DivBy2(int a)
        {
            int p = 0;
            while (a % 2 != 1)
            {
                a /= 2;
                p++;
            }
            return p;
        }
    }
    public static class Comfort
    {
        //ソート
        public static int[] OrderBy(this int[] IArr)
        {
            int[] arr = new int[IArr.Length];
            Array.Copy(IArr, arr, IArr.Length);
            Array.Sort(arr);
            return arr;
        }
        //ソート
        public static char[] OrderBy(this string IArr)
        {
            char[] arr = new char[IArr.Length];
            Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
            Array.Sort(arr);
            return arr;
        }
        //MinとMax
        public static int Max(params int[] p) => p.Max();
        public static long Max(params long[] p) => p.Max();
        public static int Min(params int[] p) => p.Min();
        public static long Min(params long[] p) => p.Min();
        //整数入力
        public static int Parse()
        {
            return int.Parse(Console.ReadLine());
        }
        //整数列入力
        public static int[] ParseArray(this string s)
        {
            return s.Split().Select(v => int.Parse(v)).ToArray();
        }
        //整数列入力
        public static long[] ParseArrayL(this string s)
        {
            return s.Split().Select(v => long.Parse(v)).ToArray();
        }
        //整数列入力
        public static int[] ParseArray()
        {
            return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
        }
        //整数列入力
        public static long[] ParseArrayL()
        {
            return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
        }
        //2整数入力
        public static void ParseArray(out int a, out int b)
        {
            var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
            a = r[0];
            b = r[1];
        }
        //3整数入力
        public static void ParseArray(out int a, out int b, out int c)
        {
            var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
            a = r[0];
            b = r[1];
            c = r[2];
        }
        //4整数入力
        public static void ParseArray(out int a, out int b, out int c, out int d)
        {
            var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
            a = r[0];
            b = r[1];
            c = r[2];
            d = r[3];
        }
        //2整数入力
        public static void ParseArray(out long a, out long b)
        {
            var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
            a = r[0];
            b = r[1];
        }
        //3整数入力
        public static void ParseArray(out long a, out long b, out long c)
        {
            var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
            a = r[0];
            b = r[1];
            c = r[2];
        }
        //4整数入力
        public static void ParseArray(out long a, out long b, out long c, out long d)
        {
            var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
            a = r[0];
            b = r[1];
            c = r[2];
            d = r[3];
        }
        //char配列のstring化
        public static string ToString(this IEnumerable<char> v)
        {
            return string.Join("", v);
        }
        //配列のstring化
        public static string Join<T>(this IEnumerable<T> v, char c)
        {
            return string.Join(c.ToString(), v);
        }
        //配列のstring化
        public static string Join<T>(this IEnumerable<T> v, string s)
        {
            return string.Join(s, v);
        }
    }
    public static class Math
    {
        //自然数判定
        public static bool IsNatural(this float v) => v - (int)v == 0;
        public static bool IsNatural(this double v) => v - (int)v == 0;
        //非重複順列
        public static long nCm(long n, long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m % 1000000007;
        }
        //素因数分解
        public static IEnumerable<int> Factor(int n)
        {
            int i = 2;
            int tmp = n;

            while (i * i <= n)
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    yield return i;
                }
                else
                {
                    i++;
                }
            }
            if (tmp != 1) yield return tmp;
        }
        //最大公約数
        public static int Gcd(int a, int b) => a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
        private static int GcdRecursive(int x, int y) => y == 0 ? x : GcdRecursive(y, x % y);
        //最大公約数
        public static long Gcd(long a, long b) => a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
        private static long GcdRecursive(long x, long y) => y == 0 ? x : GcdRecursive(y, x % y);
        //最小公倍数
        public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b);
    }
    public static class Algorithm
    {
        //2値タプル
        public class Point
        {
            public int a;
            public int b;
            public Point(int x, int y)
            {
                a = x;
                b = y;
            }
        }
        //3値タプル
        public class Tri
        {
            public int a;
            public int b;
            public int c;
            public Tri(int x, int y, int z)
            {
                a = x;
                b = y;
                c = z;
            }
        }
        //全列挙のクラス
        public class EnumAll
        {
            bool Over = false;
            int UpperValue;
            int Dimension;
            public int[] Current { private set; get; }
            public EnumAll(int Value, int Dimension)
            {
                this.Dimension = Dimension;
                UpperValue = Value;
                Current = new int[Dimension];
                Current[0] = -1;
            }
            public bool Next()
            {
                if (Over)
                    return false;
                bool flag = false;
                for (int i = 0; i < Dimension; i++)
                {
                    if (++Current[i] >= UpperValue)
                        Current[i] = 0;
                    else
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    Over = true;
                    return false;
                }
                return true;
            }
            public bool IsOver()
            {
                return Over;
            }
        }
        //Union-Find
        public class UnionFind
        {
            private int[] Parent;
            private int GetRoot(int v)
            {
                if (Parent[v] < 0)
                    return v;
                else
                    return Parent[v] = GetRoot(Parent[v]);
            }
            public UnionFind(int size)
            {
                Parent = new int[size];
                for (int i = 0; i < size; i++)
                    Parent[i] = -1;
            }
            public bool AreGrouped(int a, int b)
            {
                return GetRoot(a) == GetRoot(b);
            }
            public void Connect(int a, int b)
            {
                a = GetRoot(a);
                b = GetRoot(b);
                if (a == b) return;
                if (Parent[b] < Parent[a])
                {
                    Parent[b] += Parent[a];
                    Parent[a] = b;
                }
                else
                {
                    Parent[a] += Parent[b];
                    Parent[b] = a;
                }
            }
            public int GetGroupSize(int a)
            {
                return -Parent[GetRoot(a)];
            }
        }
    }
}


Measured memory_bytes: 48480