Assassin's Steps
Difficulty: Hard

Training to be an assassin is not easy, especially when training under someone as accomplished as Master <a href="https://www.facebook.com/manavcool.sethi">Al-Manav</a>. An assassin must learn to how to take the correct steps while walking stealthily in order to become a master assassin. Therefore, a particular training exercise concentrates on making the novice assassin walk in a straight line, taking his steps in the complicated assassin manner.

<a href="http://assassinscreed.wikia.com/wiki/Alta%C3%AFr_Ibn-La%27Ahad">Altair</a> is still in training, and makes mistakes when walking in a straight line. In one particular training instance, he has taken some steps, but may have committed some mistakes. That is, he may have taken some steps incorrectly in one or more of the previous steps. Given the probabilities of how likely he was to perform each step correctly, what should he do?

There are three possible choices for him at any time:

1. Continue walking to the end. Altair knows he will take the rest of the steps correctly. If one of the earlier steps was wrong, Master Al-Manav will make him take all the steps again -- but he knows he will perform the steps correctly the second time.

2. Jump back some number of steps, and then complete the steps as in option 1. If one of the steps over which he did not jump back was wrong, he will have to walk all the steps again, knowing that he will perform the steps correctly the second time.

3. Start from the beginning again. He knows he will perform the steps correctly this time.

Altair wishes to minimize the expected number of additional steps needed. Each forward step in the exercise costs 1 step; and each back jump also costs 1 step.

See the example below for explanation.

**Example**

Suppose the training exercise has 7 steps, and Altair has already taken the first two steps, but had a 30% chance of committing a mistake when taking each one of them. Then there are four possible cases:

_Case 1_: He took both the steps without error. This occurs with probability 0.7 * 0.7 = 0.49.  

_Case 2_: He took the first step correctly but made a mistake while taking the second step. This occurs with probability 0.7 * 0.3 = 0.21.  

_Case 3_: He took the second step correctly but made a mistake while taking the first step. This occurs with probability 0.3 * 0.7 = 0.21.  

_Case 4_: He made a mistake while taking both the steps. This occurs with probability 0.3 * 0.3 = 0.09.  

Altair does not know how many mistakes he actually committed, but for any possible strategy, he can compute the expected number of steps required for using the strategy. This is explained in the table given below:

												Case 1  Case 2  Case 3  Case 4  Expected
    Probability									0.49	0.21	0.21	0.09	-
    Additional steps if he keeps on walking		5		12		12		12		8.57
    Additional steps if he jumped back once		7		7		14		14		9.1
    Additional steps if he jumped back twice  	9		9		9		9		9
    Additional steps if restarted immediately	7		7		7		7		7
  
<br>If he keeps on walking, then there is a 0.49 probability that he will need 5 additional steps, and a 0.51 probability that he will need 12 additional steps. If he repeated the trial many times, then he would use 5 additional steps 49% of the time, and 12 additional steps the remaining 51% of the time, so the average number of additional steps needed would be 0.49 * 5 + 0.51 * 12 = 8.57. However in this case, it would be better for him to restart immediately, which requires 7 additional steps.

**Input Format**

The first line of the input contains _T_, the number of test cases. Each test case begins with a line containing two integers, _A_ and _B_. _A_ is the number of steps that Altair has already taken, and _B_ is the total number of steps in the exercise.

The next line contains _A_ real numbers: _P_<sub>1</sub>, _P_<sub>2</sub>, ..., _P_<sub>A</sub>. _P_<sub>_i_</sub> is the probability that Altair correctly took the i<sup>th</sup> step in the exercise.

**Output Format**

Output one line corresponding to each test case, containing the expected number of additional steps Altair needs (i.e. not counting the steps he has taken so far), assuming that the optimal strategy is chosen. The error in the answer must not exceed 10<sup>-6</sup>.

**Constraints**

1 &le; _T_ &le; 20  
1 &le; _A_ < _B_ &le; 10<sup>5</sup>  
0 &le; _P_<sub>_i_</sub> &le; 1  

**Sample Input** 

    3
    2 7
    0.7 0.7
    1 25
    1
    4 4
    1 0.95 0.1 0.15

**Sample Output**

    7.000000
    24.000000
    3.943000


Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (Python):
    import java.util.Scanner;

    public class AssassinSteps  {

        public static double calculateMinSteps(int A, int B, double prob[]) {

            double sol = Double.MAX_VALUE;

            double p = 1;
            for (int c = 1; c<=A; c++) {
                p *= prob[c-1];
                int D = A-c;
                sol = Math.min(sol, p*(2*D+B-A) +  (1-p) * (2*D+2*B-A));
            }

            sol = Math.min(sol, B);
            return sol;
        }

        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int numTests = in.nextInt();
            int a,b;
            double p[] = new double[100002];

            for(int i=0; i< numTests; i++)
            {
                a = in.nextInt();
                b = in.nextInt();

                for(int j=0; j<a;j++)
                {
                    p[j] = in.nextDouble();
                }

                try {
                    System.out.println(String.format("%.6f", calculateMinSteps(a,b,p)));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            in.close();
        }
    }