Since he learned Rust, Dario is now able to write software that would have never been possible with inferior languages such as C/C++. For example, he recently wrote a software that can predict with perfect accuracy the stock market prices for the next N days. Knowing these prices, he is now looking for a strategy that will make him rich.
Dario selected individual stocks, and for each of them he computed the buying price and selling price for each of the consecutive days. For example, let’s say that Dario’s list contains stocks ([A]pple, [F]acebook, [G]oogle) and that he computed their prices for consecutive days:
Day | Buy [A] | Sell [A] | Buy [F] | Sell [F] | Buy [G] | Sell [G] |
---|---|---|---|---|---|---|
1 | 5 | 3 | 6 | 2 | 5 | 4 |
2 | 8 | 6 | 7 | 6 | 6 | 5 |
The prices in the list are expressed in Euro, and are always integers. The total starting budget that Dario can invest is Euro. For the purpose of this problem, we assume that it’s possible to buy any fraction of a stock (e.g. you could buy of an Apple stock on the first day for Euro). Help Dario find the maximum profit that he can make by optimally investing Euro over those days.
Input data
The first line contains two integers and .
lines follow: the -th line contains pairs of integers: the buying price and selling price for the -th stock on the -th day.
Output data
You need to write a single line with a number: the maximum possible amount of Euro that Dario can have at the end of the days. The answer will be considered correct if the absolute or relative error is lower than .
Constraints and clarifications
- ;
- ;
- It is guaranteed that the answer will fit in a bit floating point variable (double).
# | Score | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 25 | |
3 | 42 | |
4 | 33 | No additional limitations. |
Example 1
stdin
2 3
5 3 6 2 5 4
8 6 7 6 6 5
stdout
1.2
Explanation
In the first sample case, Dario can buy of the first stock on the first day (when it costs Euro) and sell it on the second day (when it sells for Euro), scoring = Euro.
Example 2
stdin
3 3
5 3 6 2 5 4
8 6 7 6 6 5
14 13 15 14 11 9
stdout
2.6
Explanation
In the second sample case note that first two days are unchanged. One almost-optimal strategy in this case would be to reinvest the Euro of the second day by buying = units of the second stock, which can be sold on the last day for = Euro. However, there is an even better solution: keep the units of the first stock bought on the first day, and sell it on the third day for = Euro!