cho.sh
Notes
Loading...

Card Game

Time limit

2s

Memory limit

128 MB

Problem

There are 36 playing cards, divided into 9 piles of 4 cards each. Every card is face up. A card is written as a two-character string: the first character is its rank (6, 7, 8, 9, T, J, Q, K, or A), and the second character is its suit (S, D, H, or C).

In one move, you may choose only the top cards of two different piles. If the two chosen cards have the same rank, both cards are removed. The game succeeds if all cards are removed after 18 moves.

Whenever there is more than one removable pair, one of those pairs is chosen uniformly at random. If at some point there is no removable pair before all cards have been removed, the game fails.

Given the initial state of the piles, compute the probability that the game succeeds.

Input

The input contains 9 lines. Each line contains 4 space-separated card strings for one pile, ordered from the bottom card to the top card.

Output

Print the probability that the game succeeds. An absolute or relative error of up to 10^-6 is accepted.