let inf = 1 lsl 40
let n, ma, mb = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let abcs = Array.init n @@ fun _ -> Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let dp = Array.(init n @@ fun _ -> make_matrix 401 401 inf)
let a, b, c = abcs.(0)
let ans = ref inf
let _ = Array.(iter (fun a -> a.(0).(0) <- 0) dp; dp.(0).(a).(b) <- c; for i = 1 to n - 1 do let a, b, c = abcs.(i) in for j = 1 to 400 do for k = 1 to 400 do dp.(i).(j).(k) <- min dp.(i - 1).(j).(k) (if j >= a && k >= b then dp.(i - 1).(j - a).(k - b) + c else inf) done done done; iteri (fun i -> iteri (fun j p -> if p > 0 && i * mb = j * ma then ans := min !ans p)) dp.(n - 1)); Printf.printf "%d\n" @@ if !ans = inf then -1 else !ans