import Data.Array.IO
import Data.Array.Unboxed
import Control.Monad

inf = 10^9

main = do
  (n:ma:mb:_) <- getLine >>= return . map read . words :: IO [Int]
  dat <- getContents >>= return . map (map read . words) . lines :: IO [[Int]]

  arr <- newArray ((0,0,0),(n*10,n*10,n)) inf :: IO (IOArray (Int,Int,Int) Int)

  writeArray arr (0,0,0) 0
  forM_ (zip [0..] dat) $ \(k, (a:b:c:_)) -> do
    forM_ [0..n*10] $ \i -> do
      forM_ [0..n*10] $ \j -> do
        readArray arr (i,j,k) >>= \c1 -> do
          when (c1 /= inf) $ do
            readArray arr (i,j,k+1) >>= \c2 -> writeArray arr (i,j,k+1) (min c1 c2)
            readArray arr (i+a,j+b,k+1) >>= \c2 -> writeArray arr (i+a,j+b,k+1) (min (c1+c) c2)
  
  res <- forM (takeWhile (\(a,b) -> a<=n*10 && b<=n*10) $ map (\r -> (ma*r,mb*r)) [1..]) (\(a,b) -> readArray arr (a,b,n)) >>= return . filter (/=inf)

  print $ if res == [] then -1 else minimum res
