#P1968. Optimal Currency Trading

    ID: 15250 Type: Default 1000ms 256MiB

Optimal Currency Trading

Optimal Currency Trading

In the coming days, David will learn the exchange rates between the US dollar and the German mark. He starts with \(100\) dollars. On each day, given the known exchange rate \(r\) (which means \(1\) USD = \(r\) DEM), David can choose to exchange all his money from USD to DEM or from DEM to USD, or simply hold his current currency.

Your task is to help David decide when to exchange currencies so that he obtains the maximum possible amount of dollars at the end.

Note: At any day, the conversion is done for all of the money using that day’s exchange rate. It is assumed that conversions are free of commission.

The answer should be computed optimally using the exchange rates for the \(N\) days given in the input.

inputFormat

The first line contains a positive integer \(N\), representing the number of days. Each of the next \(N\) lines contains a floating-point number representing the exchange rate \(r\) on that day (i.e. \(1\) USD = \(r\) DEM).

outputFormat

Output the maximum amount of dollars that can be obtained after performing zero or more exchanges optimally. The result should be printed as a floating-point number with at least 6 decimal places of precision.

sample

3
1.25
0.88
0.95
142.045455