import qualified Data.Map as M
main=print.solve.map(map read.words).lines=<<getContents
solve([n,ma,mb]:abcs)=if null r then -1 else minimum r where
  r=map snd.filter(\((a,b),_)->a*b/=0&&a*mb==b*ma).M.toList$foldr g (M.singleton(0,0)0)abcs
  g[a,b,c]m=foldr(\((x,y),z)m->M.insertWith min(a+x,b+y)(c+z)m)m.M.toList$m