local mmi = math.min
local inf = 0
local t = {}
for i = 1, 400 * 400 do t[i] = 0 end

local n, ma, mb = io.read("*n", "*n", "*n")
for i = 1, n do
  local a, b, c = io.read("*n", "*n", "*n")
  for ia = 400, 1, -1 do
    for ib = 400, 1, -1 do
      local src = (ia - 1) * 400 + ib
      if 0 < t[src] then
        local dst = (ia + a - 1) * 400 + ib + b
        if t[dst] == 0 then
          t[dst] = t[src] + c
        else
          t[dst] = mmi(t[dst], t[src] + c)
        end
      end
    end
  end
  local first_dst = (a - 1) * 400 + b
  if t[first_dst] == 0 then
    t[first_dst] = c
  else
    t[first_dst] = mmi(t[first_dst], c)
  end
end

local ret = -1
for ia = 1, 400 do
  if ia % ma == 0 then
    ib = math.floor(ia * mb / ma)
    if ib <= 400 then
      local c = t[(ia - 1) * 400 + ib]
      if 0 < c then
        if ret < 0 then
          ret = c
        else
          ret = mmi(ret, c)
        end
      end
    end
  end
end
print(ret)
