using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    struct Material
    {
        public int A { get; }
        public int B { get; }
        public int C { get; }

        public Material(int a, int b, int c)
        {
            A = a;
            B = b;
            C = c;
        }
    }

    class Program
    {
        const int Inf = 1 << 25;

        static int Solve(Material[] M, int ma, int mb, int?[,,] memo, int no = 0, int a = 0, int b = 0)
        {
            if (no == M.Length)
            {
                return (a > 0 && b > 0 && a * mb == b * ma) ? 0 : Inf;
            }

            if (memo[no, a, b] != null)
            {
                return memo[no, a, b].GetValueOrDefault();
            }

            return (memo[no, a, b] = Min(Solve(M, ma, mb, memo, no + 1, a, b),
                                         Solve(M, ma, mb, memo, no + 1, a + M[no].A, b + M[no].B) + M[no].C))
                                         .GetValueOrDefault();
        }

        static void Main(string[] args)
        {
            int n, ma, mb;
            ReadInt(out n, out ma, out mb);

            Material[] M = (from _ in Enumerable.Repeat(0, n)
                            let cols = ReadIntArray()
                            select new Material(cols[0], cols[1], cols[2])).ToArray();

            int ans = Solve(M, ma, mb, new int?[n, 410, 410]);
            Console.WriteLine(ans >= Inf ? -1 : ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 64352