cho.sh
Notes
Loading...

Coin Passing Game

Time limit

2s

Memory limit

128 MB

Problem

N students sit around a round table in order from 1 to N. Student i has student i+1 on the right, and student N has student 1 on the right.

The game starts when student K receives a coin. Whenever a student receives the coin, that student passes it either to the immediate right neighbor or to the immediate left neighbor according to a fixed probability. The probability of passing to the right may be different for each student.

The game ends as soon as every student has received the coin at least once. The winner is the student whose first reception of the coin completes this condition.

Given the right-passing probabilities for students 1 through N-1, compute the probability that student N is the winner. Student N's passing probability is unnecessary: if student N receives the coin before every other student has received it, student N cannot be the winner; if every other student has already received it before student N receives it, the game ends immediately.

Input

The first line contains the number of students N and the starting student K.

  • 1 <= N <= 50
  • 1 <= K <= N

The second line contains N-1 real numbers. In order, they are the probabilities that students 1 through N-1 pass the coin to the right. If the probability is P, the probability of passing to the left is 1-P.

Each probability has at most two digits after the decimal point, and no probability is 0 or 1.

Output

Print the probability that student N is the winner.

An absolute or relative error of at most 10^-6 is accepted.