#P1297. Misaligned Answers

    ID: 14584 Type: Default 1000ms 256MiB

Misaligned Answers

Misaligned Answers

In this problem, gx and lc take part in the NOIP preliminary contest. One of the question types is single-choice questions, meaning that for each question only one option is correct.

The exam consists of \(n\) single-choice questions. The \(i\)-th question has \(a_i\) options labeled \(1,2,3,\ldots, a_i\). Each option is equally likely to be the correct answer.

lc adopts the strategy of randomly selecting an answer from \(1\) to \(a_i\) for each question, so his expected number of correct answers is \(\sum_{i=1}^{n} \frac{1}{a_i}\).

gx, however, answers every question correctly. But when transferring his answers to the answer sheet, he makes a mistake: the answer for the \(i\)-th question is recorded in the \(i+1\)-th position, and the answer for the \(n\)-th question is recorded in the first position.

Assuming that gx answered every question correctly (i.e. his original answers are correct), his recorded answer for question \(i\) becomes the original answer of question \(i-1\) (with the cyclic property that question 1 gets the answer of question \(n\)).

Thus, for question \(i\), let the correct answer be \(A_i\) (a uniformly random selection from \(\{1, 2, \ldots, a_i\}\)) and gx's recorded answer be \(A_{i-1}\) (with the index taken modulo \(n\), meaning that \(A_0 = A_n\)). The answer for question \(i\) is correct if \(A_{i-1} = A_i\). Since \(A_{i-1}\) and \(A_i\) are independent, the probability that \(A_{i-1} = A_i\) is given by:

[ P_i = \frac{\min(a_{i-1}, a_i)}{a_{i-1}\cdot a_i} \quad (\text{with } a_0 \equiv a_n) ]

Therefore, the expected number of correctly answered questions is:

[ \text{Expected Correct} = \sum_{i=1}^{n} \frac{\min(a_{i-1}, a_i)}{a_{i-1}\cdot a_i} ]

Output this expected number. You may assume that an absolute or relative error of up to \(10^{-6}\) is acceptable.

inputFormat

The first line contains an integer \(n\) (\(2 \leq n \leq 10^5\)) representing the number of questions.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(1 \leq a_i \leq 10^9\)) — the number of options for each question.

outputFormat

Output a single number — the expected number of correctly answered questions by gx. The answer is accepted if the absolute or relative error does not exceed \(10^{-6}\).

sample

2
2 3
0.666666667