let lim, inf = 400, 10101010101010
let () =
  Scanf.scanf "%d %d %d" @@ fun n ma mb ->
  let x = Array.init n (fun _ -> Scanf.scanf " %d %d %d" (fun a b c -> a,b,c)) in
  let dp = Array.make_matrix (lim+1) (lim+1) inf in
  dp.(0).(0) <- 0;
  x |> Array.iter (fun (a,b,c) ->
    for i = 400 downto a do
      for j = 400 downto b do
        dp.(i).(j) <- min dp.(i).(j) (dp.(i-a).(j-b) + c)
    done done);
  Array.init (lim / max ma mb) (fun i -> dp.((i+1)*ma).((i+1)*mb))
  |> Array.fold_left min inf
  |> fun c -> Printf.printf "%d\n" (if c = inf then -1 else c)