eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків

Roses

Valentine has decided to congratulate all of his \textbf{N} girlfriends by giving each one a yellow rose. In the nearby flower market yellow roses are sold by exactly two vendors. Each of them has an unlimited amount of roses; however, they sell roses only in bouquets (so you can only buy a certain amount of roses at a time). At the first vendor you can buy a bouquet of \textbf{A} roses for \textbf{B} Euros; at the second vendor -- a bouquet of \textbf{C} roses for \textbf{D} Euros. \textbf{A}, \textbf{B}, \textbf{C}, and \textbf{D} are all positive integers. If Valentine can buy more than \textbf{N} roses for a smaller amount of money than buying precisely \textbf{N} roses, he will buy more than \textbf{N} roses and gift the leftover to any of the two lovely salesgirls. Write a program that calculates the minimum amount of money in Euros for which Valentine can buy at least \textbf{N} roses! \InputFile The input file contains exactly one line. The first and only line contains five integers: \textbf{N}, \textbf{A}, \textbf{B}, \textbf{C}, and \textbf{D}; every two consecutive numbers are separated by a single whitespace. The value of \textbf{N} does not exceed \textbf{10^15}, the values of \textbf{A}, \textbf{B}, \textbf{C}, and \textbf{D} do not exceed \textbf{10^5}. \OutputFile The output file should contain one line with one natural number -- the minimum amount of money in Euros for which Valentine can buy at least \textbf{N} roses. It is known that for all given test cases the correct answer does not exceed \textbf{10^18}.
Ліміт часу 0.5 секунд
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
5 1 4 3 6
Вихідні дані #1
12
Джерело BOI-2012