import Data.Bool
import qualified Data.ByteString.Char8 as C
import Data.List
import qualified Data.Map.Strict as M

main = C.interact $ put . sol . get

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines

put = C.pack . show

sol :: [[Int]] -> Int
sol ([n,ma,mb]:[a1,b1,c1]:abcs)= bool (-1) mn (mn<mx)
  where
  mx = 100*n
  mn = fst $ foldl' f (mx, M.singleton [a1,b1] c1) abcs
  f (s,mp) [a,b,c] = (minimum $ s:M.elems mp'', M.unionWith min mp mp')
    where
    mp' = M.map ((+) c) $ M.mapKeys (zipWith (+) [a,b]) mp
    mp'' = M.filterWithKey (\[a,b] _ -> a*mb==b*ma) mp'