Speedrun

Given per-road win probabilities, choose checkpoints to save at so the expected time to reach checkpoint n is minimized.

Medium7ProbabilityDynamic programmingNo attempts yetTime limit8sMemory limit512 MB

Problem

Infinite Chronicle -Princess Castle- is a simple role playing game. It has n+1n+1 checkpoints numbered 00 through nn, and for each i=1,2,,ni = 1, 2, \dots, n there is exactly one one way road running from checkpoint i1i-1 to checkpoint ii. The game starts at checkpoint 00 and ends at checkpoint nn. Monsters appear on the roads and the hero fights them. You can save your progress at any checkpoint, and if you lose a battle you can restart the game from the checkpoint where you saved last. When the game starts, progress is saved at checkpoint 00 automatically and that save takes no time.

Rabbit Hanako likes this game and now wants to speedrun it. She is an expert player, but random factors keep her from winning every battle. For each ii she estimated the probability pip_i of winning all the battles on the road from checkpoint i1i-1 to checkpoint ii. Every time she sets out from checkpoint i1i-1, exactly one minute later she is at checkpoint ii with probability pip_i, and back at the checkpoint of her last save with probability 1pi1 - p_i.

Saving at a checkpoint also takes one minute, so passing a checkpoint without saving is sometimes faster. Compute the minimum expected time needed to finish the game.

Input

The input holds several datasets, at most 50 of them. Each dataset has two lines. The first line has one integer nn (1n1051 \le n \le 10^5), the number of roads. The second line has nn numbers p1,p2,,pnp_1, p_2, \dots, p_n (0<pi10 < p_i \le 1), the winning probabilities, each written with exactly two digits after the decimal point. The last line of the input holds a single zero and is not a dataset.

Output

For each dataset print the minimum expected time in minutes on its own line, with exactly six digits after the decimal point.