local mmi, mma = math.min, math.max
local n, ma, mb = io.read("*n", "*n", "*n")
local a, b, c = {}, {}, {}
for i = 1, n do
  a[i], b[i], c[i] = io.read("*n", "*n", "*n")
end
local inf = 1000000007
local t = {}
for i = 1, 400 do
  t[i] = {}
  for j = 1, 400 do
    t[i][j] = inf
  end
end
for k = 1, n do
  for i = 400 - a[k], 1, -1 do
    for j = 400 - b[k], 1, -1 do
      t[i + a[k]][j + b[k]] = mmi(t[i + a[k]][j + b[k]], t[i][j] + c[k])
    end
  end
  t[a[k]][b[k]] = mmi(t[a[k]][b[k]], c[k])
end
local ret = -1
for i = 1, 400 do
  for j = 1, 400 do
    if i * mb == j * ma and t[i][j] < inf then
      if ret < 0 or t[i][j] < ret then
        ret = t[i][j]
      end
    end
  end
end
print(ret)
