using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.ExceptionServices;

namespace Contest
{
    class Program
    {
        private Scanner sc;
        private int N, Ma, Mb;
        private int[] A, B, C;
        public void Solve()
        {
            sc = new Scanner();
            N = sc.NextInt();
            Ma = sc.NextInt();
            Mb = sc.NextInt();
            A = new int[N];
            B = new int[N];
            C = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = sc.NextInt();
                B[i] = sc.NextInt();
                C[i] = sc.NextInt();
            }

            var dp = new int[401, 401];

            for (int i = 0; i <= 400; i++)
            {
                for (int j = 0; j <= 400; j++)
                {
                    dp[i, j] = int.MaxValue;
                }
            }

            dp[0, 0] = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = 400; j >= 0; j--)
                {
                    for (int k = 400; k >= 0; k--)
                    {
                        if (dp[j, k] != int.MaxValue)
                        {
                            if (j + A[i] <= 400 && k + B[i] <= 400)
                            {
                                dp[j + A[i], k + B[i]] = Math.Min(dp[j + A[i], k + B[i]], dp[j, k]+C[i]);
                            }
                        }
                    }
                }
            }

            int ans = int.MaxValue;
            for (int i = 1; i * Math.Max(Ma, Mb) <= 400; i++)
            {
                ans = Math.Min(dp[Ma * i, Mb * i], ans);
            }

            Console.WriteLine(ans == int.MaxValue ? -1 : ans);
        }

        static void Main() => new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private readonly char _separator;
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 13140