#P11019. [2016杭电多校]Permutation Bo

[2016杭电多校]Permutation Bo

Permutation Bo

Problem Description

There are two sequences h1hnh_1\sim h_n and c1cnc_1\sim c_n. h1hnh_1\sim h_n is a permutation of 1n1\sim n. particularly, h0=hn+1=0h_0=h_{n+1}=0. We define the expression [condition][condition] is 1 when conditioncondition is True,is 0 when conditioncondition is False. Define the function $f(h)=\sum_{i=1}^{n}{c_i[h_i>h_{i-1}~~and~~h_i>h_{i+1}]}$ Bo have gotten the value of c1cnc_1\sim c_n, and he wants to know the expected value of f(h)f(h).

Input

This problem has multi test cases(no more than 1212). For each test case, the first line contains a non-negative integer n(1n1000)n(1\leq n\leq1000), second line contains nn non-negative integer ci(0ci1000)c_i(0\leq c_i\leq 1000).

Output

For each test cases print a decimal - the expectation of f(h)f(h). If the absolute error between your answer and the standard answer is no more than 10410^{-4}, your solution will be accepted.

Sample Input

4
3 2 4 5
5
3 5 99 32 12

Sample Output

6.000000
52.833333

Author

绍兴一中

Source

2016 Multi-University Training Contest 3