Under construction

Still being built. Things may change

Largest Stock Price Decline

Interview

Time limit5sMemory limit256 MB

Summary
Given up to a million prices from a sine-cosine formula, find the largest drop from an earlier price to a later one.
Level

Easy3 of 10

Topics
Array, Greedy, Math
Solved
No attempts yet

Problem

Fatima Cynara is an analyst at Amalgamated Artichokes (AA). Like any company, AA has had good years and bad ones. Fatima studies the trend of the AA stock price, and she wants to know the largest decline in the price over a given span of time. Suppose the prices over a span were 19, 12, 13, 11, 20 and 14. Then the largest decline is 8, from the first price to the fourth. If the last price were 10 instead of 14, the largest decline would be 10, between the last two prices.

From her earlier analyses Fatima found that the stock price over any period can be modelled accurately enough by

price(k)=p⋅(sin⁡(ak+b)+cos⁡(ck+d)+2)\mathrm{price}(k) = p \cdot (\sin(ak+b) + \cos(ck+d) + 2)

where pp, aa, bb, cc and dd are constants and the angles of the sine and the cosine are in radians. Consider only integer values of kk. The decline between two prices price(i)\mathrm{price}(i) and price(j)\mathrm{price}(j) with i<ji < j is price(i)−price(j)\mathrm{price}(i) - \mathrm{price}(j). Find the largest decline in the sequence of prices.

The figure above shows the price function of the first example. The largest decline runs from the fourth price to the seventh.

Input

The first line holds six integers pp, aa, bb, cc, dd and nn separated by spaces. (1≤p≤10001 \le p \le 1000, 0≤a,b,c,d≤10000 \le a, b, c, d \le 1000, 1≤n≤1061 \le n \le 10^6)

The first five integers are the constants of the price function. The prices to consider are price(1)\mathrm{price}(1), price(2)\mathrm{price}(2), …\ldots, price(n)\mathrm{price}(n).

Output

Print the largest decline in the stock prices on one line, rounded to six decimal places. If the prices never decline, print 0.000000.

Examples3

  1. Example 1

    Input
    42 1 23 4 8 10
    
    Expected output
    104.855110
    
  2. Example 2

    Input
    100 7 615 998 801 3
    
    Expected output
    0.000000
    
  3. Example 3

    Input
    100 432 406 867 60 1000
    
    Expected output
    399.303813