프로그램 명: boi_rozes
제한시간: 1 초

Valentine has decided to congratulate all of his 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 A roses for B Euros; at the second vendor ? a bouquet of C roses for D Euros. A, B, C, and D are all positive integers.

If Valentine can buy more than N roses for a smaller amount of money than buying precisely N roses, he will buy more than 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 N roses!

입력

The input contains exactly one line. The first and only line contains five integers: N, A, B, C, and D; every two consecutive numbers are separated by a single whitespace. The value of N does not exceed 10^15 , the values of A, B, C, and D do not exceed 10^5.

출력

The output should contain one line with one natural number - the minimum amount of money in Euros for which Valentine can buy at least N roses. It is known that for all given test cases the correct answer does not exceed 10^18.

입출력 예

입력
5 1 4 3 6  

출력

12  

Comments

Valentine will buy six roses - two bouquets at the second place.

입력

22 2 3 10 14 

출력

31  

Comments
Valentine will buy one bouquet at the first place and two at the second.
출처:boi 2012 practice

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]