jtw7913 is playing blackjack for rating points at the DOJ casino. He knows both of the dealer's initial cards, including the normally hidden card, and he also knows exactly which cards remain in the deck.
The game uses one standard 52-card deck without jokers. A card is written as a two-character string consisting of its rank and suit. The rank is one of A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, and the suit is one of S, H, D, C. For example, AS is the ace of spades and TH is the ten of hearts.
Card values are defined as follows.
- Ranks
2through9have their numerical values. T,J,Q, andKare worth 10 points each.- An ace
Amay be worth either 1 or 11 points.
If a hand contains at least one ace, use the largest obtainable score not exceeding 21. If every obtainable score exceeds 21, use the smallest obtainable score. Suits do not affect scores or game results.
jtw7913 and the dealer each start with two cards. A hand is a blackjack if its initial two cards alone have score exactly 21. Reaching 21 with three or more cards is not a blackjack.
Immediately after the game starts, check for blackjacks.
- If both have blackjack, the game is a draw.
- If only jtw7913 has blackjack, jtw7913 wins by blackjack.
- If only the dealer has blackjack, jtw7913 loses.
- Otherwise, the game continues.
If the game continues, on each of his turns jtw7913 chooses either Hit or Stay.
- Hit: draw one uniformly random card from the remaining deck and add it to his hand.
- Stay: take no more cards and end his turn.
Cards of the same rank are still distinct physical cards. Therefore, the probability of drawing a rank is proportional to the number of remaining cards of that rank.
Immediately after jtw7913 draws a card, if his score exceeds 21, he busts and loses. If his score becomes exactly 21, he automatically Stays. If the deck is empty, he cannot Hit and automatically Stays.
After jtw7913 Stays, the dealer acts. The dealer must Hit on scores at most 16 and must Stay on scores at least 17. The dealer also Stays on a soft 17, where an ace is counted as 11. When the dealer Hits, one uniformly random remaining card is drawn. If the dealer's score then exceeds 21, the dealer busts. If the dealer must Hit but the deck is empty, the dealer automatically Stays.
After all actions finish, determine the result as follows.
- If jtw7913 busts, he loses.
- If jtw7913 does not bust and the dealer busts, jtw7913 wins.
- If neither busts, the higher score wins.
- Equal scores result in a draw.
Let be the number of rating points wagered. jtw7913's net profit is for a normal win, for a blackjack win, for a draw, and for a loss. Splitting, doubling down, surrender, and insurance are not allowed.
Using all known information, jtw7913 chooses actions that maximize the expected net profit at every point. Find the expected net profit when he plays optimally.
Input
The input is given from Standard Input in the following format:
Each case is given in the following format:
are jtw7913's initial cards, are the dealer's initial cards, and are the cards currently remaining in the deck.
Output
For each test case, print on one line the expected net profit when jtw7913 plays optimally.
Your answer is considered correct if its absolute or relative error does not exceed .
Constraints
- .
- .
- .
- Every card is a valid two-character representation of one of the 52 cards in a standard deck.
- Within one test case, are pairwise distinct physical cards.
- Over all test cases, .
Subtasks
Samples
Staying immediately gives a net profit of . If jtw7913 hits, he draws 5S or 6H with probability each, and optimal play afterward yields net profits and , respectively. Therefore the expected value is .
If jtw7913 hits first and continues optimally after each possible draw, the expected net profit is , which is better than the obtained by staying immediately.
jtw7913's initial two cards form a blackjack while the dealer does not have blackjack. The game therefore ends immediately with a blackjack win, for a net profit of .
jtw7913 starts with score 19. Every possible hit would bust, so staying is optimal. Considering all forced dealer draws afterward gives expected net profit .