Texas hold 'em is one of the standard poker games, originated in Texas, United States. It is played with a standard deck of cards, which has suits (spades, hearts, diamonds and clubs) and ranks (, , , and , ..., ), without jokers.
With betting aside, a game proceeds as follows.
At the beginning, each player is dealt two cards face down. These cards are called hole cards or pocket cards, and do not have to be revealed until the showdown. Then the dealer deals three cards face up as community cards, i.e., cards shared by all players. These three cards are called the "flop." The flop is followed by another community card called the turn, and then by one more community card called the river.
After the river, the game proceeds to the showdown. All players reveal their hole cards at this point. Then each player chooses five out of the seven cards, i.e., their two hole cards and the five community cards, to form a hand. The player forming the strongest hand wins the game. There are ten possible kinds of hands, listed from the strongest to the weakest:
Royal straight flush: , , , , and of the same suit. This is a special case of a straight flush.
Straight flush: Five cards in sequence (e.g., , , , , and ), all of the same suit.
Four of a kind: Four cards of the same rank.
Full house: Three cards of the same rank, plus a pair of another rank.
Flush: Five cards of the same suit, but not in sequence.
Straight: Five cards in sequence, but not of the same suit.
Three of a kind: Three cards of the same rank.
Two pairs: Two cards of the same rank, and two cards of another rank.
One pair: Two cards of the same rank.
High card: Any other hand.
For the purposes of a sequence, , , and are treated as , , and , respectively. can be seen as a rank either next above or next below , thus both ---- and ---- are possible (but not ---- or the like).
If more than one player has the same kind of hand, ties are broken by comparing the ranks of the cards.
The basic idea is to compare first those forming sets (pairs, triples or quads) then the rest of the cards, one by one from the highest-ranked to the lowest-ranked, until ties are broken. More specifically:
Royal straight flush: (ties are not broken)
Straight flush: Compare the highest-ranked card.
Four of a kind: Compare the four cards, then the remaining one.
Full house: Compare the three cards, then the pair.
Flush: Compare all cards one by one.
Straight: Compare the highest-ranked card.
Three of a kind: Compare the three cards, then the remaining two.
Two pairs: Compare the higher-ranked pair, then the lower-ranked, then the last one.
One pair: Compare the pair, then the remaining three cards.
High card: Compare all cards one by one.
The order of the ranks is , , , , , , , ..., from the highest to the lowest, except for next to in a straight regarded as lower than . Note that there are exceptional cases where ties remain. Also, note that suits are not considered at all in tie-breaking.
Here are a few examples of comparing hands (note these are only intended for explanatory purposes; some combinations cannot happen in Texas Hold 'em):
---- and ----. The former beats the latter since three of a kind is stronger than two pairs.
---- and ----. Since both are three of a kind, the triples are considered first, and in this case. is higher, hence the former is a stronger hand. The remaining cards, - and -, are not considered as the tie is already broken.
---- and ----. Both are high cards, assuming hands not of a single suit (i.e., not a flush). The three highest-ranked cards -- are the same, so the fourth highest are compared. The former is stronger since is higher than .
---- and ----. Both are one pair, with the pair of the same rank (). So the remaining cards, -- and --, are compared from the highest to the lowest, and the former wins as is higher than .
Now suppose you are playing a game of Texas Hold 'em with one opponent, and the hole cards and the opponent's cards have already been dealt. You are surprisingly telepathic and able to know the cards the opponent has. However, your ability is not so strong that you can predict which cards will appear as the turn and the river.
Your task is to write a program that calculates the probability of your winning the game, assuming the turn and the river are chosen uniformly at random from the remaining cards. You and the opponent always select the strongest possible hand available. Ties should be included in the calculation, i.e., should be counted as losses.
The input consists of multiple datasets, each of which has the following format:
\text{YourCard}_1\ \text{YourCard}_2
\text{OpponentCard}_1\ \text{OpponentCard}_2
\text{CommunityCard}_1\ \text{CommunityCard}_2\ \text{CommunityCard}_3
Each dataset consists of three lines. The first and second lines contain your and your opponent's hole cards, respectively. The third line contains the flop, i.e., the first three community cards. These cards are separated by spaces.
Each card is represented by two characters. The first one indicates the suit: (spades), (hearts), (diamonds), or (clubs). The second one indicates the rank: , , , , (), or , ..., . The end of the input is indicated by a line with "#". This should not be processed.
Print the probability on a single line. The number may contain an arbitrary number of digits after the decimal point, but should not have an absolute error greater than 10^{-6}.
Example 1