#P1654. Expected Score in Simplified OSU

    ID: 14940 Type: Default 1000ms 256MiB

Expected Score in Simplified OSU

Expected Score in Simplified OSU

In the simplified version of the popular game osu!, you are given n operations. Each operation is either a success (denoted by 1) or a failure (denoted by 0). Thus a complete game is represented as a binary string of length n.

A maximal contiguous segment of successes (i.e. a segment of consecutive 1's that is not part of a longer segment of 1's) with length X contributes a score of \(X^3\). For example, if the entire string is all 1's, then there is one segment of length n contributing \(n^3\). If there are failures that break the sequence, then each maximal block of 1's is scored separately.

You are given the number n and the success probability for each operation. Your task is to compute the expected total score over all n operations, and output the result rounded to one decimal place.

Note: In the final scoring, any ongoing streak at the end of the operations is also counted as a maximal segment.

inputFormat

The first line contains a single integer n (the number of operations).

The second line contains n space-separated real numbers, where the ith number represents the probability of success for the ith operation.

outputFormat

Output a single real number: the expected total score, rounded to one decimal place.

sample

5
0.0 0.0 0.0 0.0 0.0
0.0