Rock Paper Scissors Ranking

Given each contestant's probabilities for scissors, rock, and paper, find the probability that contestant 1 finishes in place K of the recursive elimination tournament.

Medium7ProbabilityDynamic programmingBacktrackingNo attempts yetTime limit2sMemory limit512 MB

Problem

N contestants play rock paper scissors for prizes. In one round every contestant still in the group shows scissors, rock, or paper at the same time. The round decides something only when exactly two of the three shapes appear. If everyone shows the same shape, or all three shapes appear, the round is void and the same group plays a fresh round.

When a round is decided, the contestants who showed the winning shape form the winner group and the others form the loser group. The winner group takes the upper ranks and the loser group takes the ranks right below them. Both groups keep playing the same way until only one contestant is left in them, so ranks 1 through N all get settled.

For example, suppose four contestants A, B, C, D play a round and A and C show scissors while B and D show paper. Scissors beats paper, so A and C play again to decide first and second place, and B and D play again to decide third and fourth place.

The contestants are numbered 1 through N. Contestant 1, Taehyun, has found out in advance the probability that each contestant shows each shape. The prize Taehyun wants goes to the contestant who finishes in place K. Find the probability that Taehyun gets that prize.

In every round the contestants choose their shapes independently of each other, each according to that contestant's own probabilities.

Input

The first line contains N and K. (2N122 \le N \le 12, 1KN1 \le K \le N)

Each of the next N lines contains the probabilities sis_i, rir_i, pip_i that contestant ii shows scissors, rock, and paper, separated by spaces. The three probabilities are given with up to three digits after the decimal point, 0si,ri,pi10 \le s_i, r_i, p_i \le 1, and si+ri+pi=1s_i + r_i + p_i = 1. Every contestant shows at least two different shapes, so at most one of the three probabilities is 0.

Output

Print the probability that Taehyun finishes in place K on one line, rounded to eight digits after the decimal point. Print all eight digits even when they are zero.