JOI wants to buy N pencils and goes to a nearby stationery shop.
The shop sells pencils only in fixed-size sets. Set X holds A pencils and costs B yen. Set Y holds C pencils and costs D yen.
JOI picks either set X or set Y and then buys as many copies of the chosen set as he likes. He cannot buy both kinds of set. Find the smallest amount of money needed to end up with at least N pencils.