This page is still under construction.

Parts of this page are still being built. What you see may change.

Cow Dating

Time limit2sMemory limit512 MB

Summary
Given probabilities p_i, choose a contiguous interval maximizing the chance that exactly one bull accepts, and print 10^6 times that probability rounded down.
Level

Hard8 of 10

Topics
Math, Two pointers, Probability, Prefix sum
Solved
No attempts yet

Problem

Not impressed by the lackluster dating websites currently available to cows (eHarmoony, Moosk, Plenty of Cows, and the like), Farmer John decides to launch a new cow dating site built on a proprietary matching algorithm that pairs cows and bulls according to a wide range of their mutual interests.

Searching for a partner for the Valentine's Day Barn Dance, Bessie decides to try the site. After she makes her account, FJ's algorithm gives her a list of NN possible matches (1≤N≤1061\leq N \leq 10^6). Going through the list, Bessie concludes that each bull has probability p_ip\_i (0\<p_i<10\<p\_i<1) of accepting an invitation from her to the dance.

Bessie decides to send an invitation to every bull in a contiguous interval of the list. Virtuous as always, she wants exactly one partner. Help Bessie find the maximum probability of receiving exactly one accepted invitation, assuming she chooses the right interval.

Input

The first line of input contains NN (1≤N≤1061 \leq N \leq 10^6). Each of the remaining NN lines contains 10610^6 times p_ip\_i, which is an integer.

In at least 25% of the test cases, it is further guaranteed that N≤4000N \leq 4000.

Output

Print 10610^6 times the maximum probability of receiving exactly one accepted invitation, rounded down to the nearest integer.

Notes

The maximal probability results from selecting the interval from the 2nd to the 3rd cow.

As a note, you should be somewhat careful with floating point precision when solving this problem. We advise using at least "doubles" (64-bit floating-point numbers) and not "floats" (32-bit floating point numbers).

Examples1

  1. Example 1

    Input
    3
    300000
    400000
    350000
    
    Expected output
    470000