using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            const int GETA = 10000;
            const long INI = int.MaxValue;
            (long N, long Ma, long Mb) = Slice3<long>();

            var fstNum = N / 2;
            (long t, long c)[] first = new (long, long)[fstNum];
            for (var i = 0; i < fstNum; ++i)
            {
                (long a, long b, long c) = Slice3<long>();
                var t = Ma * b - Mb * a;
                first[i] = (t, c);
            }
            void fnc(int bits, out long[] dp, (long t, long c)[] vs)
            {
                dp = Enumerable.Repeat(INI, GETA * 2).ToArray();
                var lst = (1L << bits);
                for (var i = 1; i < lst; ++i)
                {
                    var t = i;
                    var tSum = 0L;
                    var cSum = 0L;
                    for (var b = 0; b < bits; ++b)
                    {
                        if (0 != (t & 1))
                        {
                            tSum += vs[b].t;
                            cSum += vs[b].c;
                        }
                        t >>= 1;
                    }
                    dp[GETA + tSum] = Min(dp[GETA + tSum], cSum);
                }
                return;
            }
            long[] dp1;
            fnc((int)fstNum, out dp1, first);
            var ltrNum = N - fstNum;
            (long t, long c)[] latter = new (long, long)[ltrNum];
            for (var i = 0; i < ltrNum; ++i)
            {
                (long a, long b, long c) = Slice3<long>();
                var t = Ma * b - Mb * a;
                latter[i] = (t, c);
            }
            long[] dp2;
            fnc((int)ltrNum, out dp2, latter);

            var ans = Min(dp1[GETA], dp2[GETA]);
            for (var i = -4010; i < 4010; ++i)
                ans = Min(ans, dp1[GETA + i] + dp2[GETA - i]);
            if (ans == INI)
                WriteLine(-1);
            else
                WriteLine(ans);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28600