package main

import (
	"math"
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func perm(N int, G [][]bool, size int, used []bool, order []int) int {
	if size == N {
		return 1;
	}
	ans := 0
	for i := 0; i < N; i++ {
		if used[i] {
			continue
		}
		if G[order[size - 1]][i] == false {
			continue
		}
		used[i] = true;
		order[size] = i;
		ans += perm(N, G, size + 1, used, order)
		used[i] = false;
	}
	return ans;
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	X := io.NextInt()
	Y := io.NextInt()
	K := 400
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = io.NextInt()
		B[i] = io.NextInt()
		C[i] = io.NextInt()
	}
	// dp[N][A][B]
	dp := make([][][]int, N)
	for i := 0; i < N; i++ {
		dp[i] = make([][]int, K + 1)
		for j := 0; j <= K; j++ {
			dp[i][j] = make([]int, K + 1)
			for k := 0; k <= K; k++ {
				dp[i][j][k] = math.MaxInt64
			}
		}
	}
	dp[0][0][0] = 0
	dp[0][A[0]][B[0]] = C[0]
	for i := 1; i < N; i++ {
		for j := 0; j <= K; j++ {
			for k := 0; k <= K; k++ {
				if dp[i - 1][j][k] != math.MaxInt64 {
					var x *int
					x = &dp[i][j][k]
					*x = intMin(*x, dp[i - 1][j][k])
					x = &dp[i][j + A[i]][k + B[i]]
					*x = intMin(*x, dp[i - 1][j][k] + C[i])
				}
			}
		}
	}
	ans := math.MaxInt64
	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			if a % X != 0 || b % Y != 0 {
				continue
			}
			k := a / X
			if b == k * Y && dp[N - 1][a][b] != math.MaxInt64 {
				//Log("a", a)
				//Log("b", b)
				ans = intMin(ans, dp[N - 1][a][b])
			}
		}
	}
	if ans == math.MaxInt64 {
		io.PrintLn(-1)
	} else {
		io.PrintLn(ans)
	}
}

Measured memory_bytes: 58112