This page is still under construction.

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

Balance Beam

Time limit2sMemory limit512 MB

Summary
Choose at each beam position a cash value or a fair coin random walk stopped at the ends, maximizing expected payment for every starting position.
Level

Hard8 of 10

Topics
Dynamic programming, Math, Probability, Implementation
Solved
No attempts yet

Problem

To save money for a new stall in her barn, Bessie the cow has started performing in the local circus, showing off her remarkable sense of balance as she carefully walks back and forth on an elevated balance beam!

The amount of money Bessie earns in her performance depends on where she ultimately jumps off the beam. The beam has positions labeled 0,1,…,N+10, 1, \ldots, N+1 from left to right. If Bessie ever reaches 00 or N+1N+1, she falls off one of the ends of the beam and sadly receives no payment.

If Bessie is at a given position kk, she can do either of the following:

  1. Flip a coin. If she sees tails, she goes to position k−1k-1, and if she sees heads, she goes to position k+1k + 1 (that is, probability 12\frac{1}{2} of either occurrence).
  2. Jump off the beam and receive payment of f(k)f(k) (0≤f(k)≤109)(0 \leq f(k) \leq 10^9).

Bessie realizes that she may not be able to guarantee any particular payment outcome, since her movement is governed by random coin flips. However, based on the location where she starts, she wants to determine what her expected payment will be if she makes an optimal sequence of decisions ("optimal" meaning that the decisions lead to the highest possible expected payment). For example, if her strategy earns her payment of 1010 with probability 1/21/2, 88 with probability 1/41/4, or 00 with probability 1/41/4, then her expected payment will be the weighted average 10(1/2)+8(1/4)+0(1/4)=710(1/2) + 8(1/4) + 0(1/4) = 7.

Input

The first line of input contains NN (2≤N≤1052 \leq N \leq 10^5). Each of the remaining NN lines contains f(1)…f(N)f(1) \ldots f(N).

Output

Output NN lines. On line ii, print 10510^5 times the expected value of payment if Bessie starts at position ii and plays optimally, rounded down to the nearest integer.

Examples1

  1. Example 1

    Input
    2
    1
    3
    
    Expected output
    150000
    300000