Planet Cake

In the planet Cake, home of the Master Masao, a casino offers a particular game. There is an array of probabilities p1,,p2m+1p_1, \ldots, p_{2m+1} for some natural number mm. At every moment, a coin has probability pip_i of landing heads when flipped. If it indeed lands heads, the next time the probability will be pi+1p_{i+1}. Otherwise, the probability will be pi1p_{i-1}. The initial “state” is m+1m+1. Before playing, you must decide a number kk between 11 and m+1m+1. Afterwards, you flip the coin kk times. You win if the total number of times the coin landed heads is an odd number.

Given the probabilities of a coin, compute the probability of winning a game assuming an optimal strategy.

Input

Input consists of several cases, each with an odd number nn followed by nn probabilities. Assume n<50n < 50.

Output

For every case, print the probability of winning with four digits after the decimal point. The input cases have no precision issues.

Problem information

Author: Xavier Martínez

Generation: 2026-01-25T10:06:11.034Z

© Jutge.org, 2006–2026.
https://jutge.org