#[allow(unused_imports)]
use std::char::from_digit;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::fs::File;
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Stdin, Stdout, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

type BoxResult<T> = Result<T, Box<std::error::Error>>;


fn main() {
    let mut scanner = Scanner::new(stdin());
    let line = scanner.read_vector::<usize>().unwrap();
    let (n, a, b) = (line[0], line[1], line[2]);
    let mut arr = vec![];
    for _ in 0..n {
        let line = scanner.read_vector::<usize>().unwrap();
        arr.push((line[0], line[1], line[2]));
    }
    let ans = solve(n, a, b, &arr);
    if ans < std::usize::MAX {
        println!("{}", ans);
    } else {
        println!("-1");
    }
}

fn solve(n: usize, a: usize, b: usize, arr: &[(usize, usize, usize)]) -> usize {
    let mut map = HashMap::new();
    let rest = power_set(&arr[(n / 2)..]);
    for (x, y, c) in rest.into_iter() {
        if map.contains_key(&(x, y)) {
            let val = map.get_mut(&(x, y)).unwrap();
            if c < *val {
                *val = c;
            }
        } else {
            map.insert((x, y), c);
        }
    }
    let max_val = 10 * (n - n / 2);
    let mut minimum_cost = std::usize::MAX;
    let all_cands = power_set(&arr[..(n / 2)]);
    for (x, y, c) in all_cands.into_iter() {
        if c >= minimum_cost {
            continue;
        }
        let mut i = if x % a == 0 { 0 } else { a - x % a };
        while i <= max_val {
            let sum = ((x + i) * b) / a;
            if sum < y {
                i += a;
                continue;
            }
            let j = sum - y;
            if j > max_val {
                break;
            }
            if !map.contains_key(&(i, j)) {
                i += a;
                continue;
            }
            let cost = map.get(&(i, j)).unwrap();
            if c + *cost > 0 {
                minimum_cost = min(c + *cost, minimum_cost);
            }
            i += a;
        }
    }
    minimum_cost
}

fn power_set(arr: &[(usize, usize, usize)]) -> Vec<(usize, usize, usize)> {
    let n = arr.len();
    let mut set = vec![(0, 0, 0)];
    for i in 0..n {
        let mut new_set = Vec::with_capacity(2 * set.len());
        while set.len() > 0 {
            let (a, b, c) = set.pop().unwrap();
            new_set.push((a, b, c));
            new_set.push((a + arr[i].0, b + arr[i].1, c + arr[i].2));
        }
        set = new_set;
    }
    set
}


#[allow(dead_code)]
struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}
impl<R> Scanner<R>
where
    R: Read,
{
    #[allow(dead_code)]
    fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn read_line(&mut self) -> BoxResult<String> {
        self.reader.read_line(&mut self.buffer)?;
        let cloned = self.buffer.trim().to_string();
        self.buffer.clear();
        Ok(cloned)
    }
    #[allow(dead_code)]
    fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }
    #[allow(dead_code)]
    fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }
    #[allow(dead_code)]
    fn read_matrix<T>(&mut self, lines: usize) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
    #[allow(dead_code)]
    fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}


Measured memory_bytes: 40984