This page is still under construction.

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

Speedrun

Time limit8sMemory limit512 MB

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

Medium7 of 10

Topics
Probability, Dynamic programming
Solved
No attempts yet

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 i−1i-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 i−1i-1 to checkpoint ii. Every time she sets out from checkpoint i−1i-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 1−pi1 - 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 (1≤n≤1051 \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<pi≤10 < 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.

Examples2

  1. Example 1

    Input
    2
    0.50 0.40
    2
    0.70 0.60
    4
    0.99 1.00 1.00 0.01
    0
    
    Expected output
    5.500000
    4.047619
    104.010101
    
  2. Example 2

    Input
    1
    1.00
    1
    0.01
    1
    0.50
    0
    
    Expected output
    1.000000
    100.000000
    2.000000