jtw7913 went all-in immediately after the flop was revealed while playing Texas Hold'em at the DOJ casino. The opponent called, so both players' hole cards are now known.
jtw7913 also knows the cards that were originally scheduled to appear on the turn and the river. However, if those two cards appear as scheduled, victory is not guaranteed. jtw7913 asks the DOJ god dadas to change the turn and river cards.
dadas can choose new cards for the turn and river. The cost of choosing a replacement card depends only on its rank; cards of the same rank have the same cost regardless of suit.
If the card originally scheduled for a position is used at that same position, the cost for that position is .
- Using the originally scheduled turn card on the turn costs .
- Using the originally scheduled river card on the river costs .
- Otherwise, the cost corresponding to the rank of the chosen card must be paid.
For example, suppose the original turn card is AS and the original river card is KH. Using AS on the turn or KH on the river costs . Using AH on the turn still costs the Ace-rank cost because it is a different physical card. Using KH on the turn and AS on the river costs both corresponding rank costs because both cards differ from the cards originally scheduled for those positions.
A card is represented by a two-character string. The first character is its rank and is one of 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A, where T means . The second character is its suit and is one of S, H, D, C, representing spades, hearts, diamonds, and clubs. Suits have no relative order.
The four hole cards and the three flop cards, seven cards in total, have already been used and cannot be chosen as the turn or river. The turn and river must also be different physical cards.
After the final board is completed, each player chooses the strongest five-card hand from their two hole cards and the five board cards. The hand categories, from strongest to weakest, are as follows.
- Straight flush: five cards of the same suit with consecutive ranks. Compare the highest rank.
- Four of a kind: four cards of the same rank. Compare the four-of-a-kind rank first, then the kicker.
- Full house: three cards of one rank and two cards of another rank. Compare the triplet rank first, then the pair rank.
- Flush: five cards of the same suit. Sort the five ranks in descending order and compare them lexicographically.
- Straight: five cards of consecutive ranks regardless of suit. Compare the highest rank.
- Three of a kind: three cards of the same rank. Compare the triplet rank first, then the two kickers in descending order.
- Two pair: two different ranks appearing twice each. Compare the higher pair, then the lower pair, then the kicker.
- One pair: two cards of the same rank. Compare the pair rank first, then the three kickers in descending order.
- High card: any hand not belonging to a stronger category. Sort the five ranks in descending order and compare them lexicographically.
An Ace normally has rank . In the straight A, 2, 3, 4, 5, the Ace may be used as rank , and the straight is treated as five-high. Wrap-around straights with an Ace in the middle are not allowed. A royal flush is simply an Ace-high straight flush.
If the two players' final best hands are exactly equal, the result is a draw. A draw is not considered a win for jtw7913.
Choose the turn and river so that jtw7913 wins, minimizing the total cost. If no winning choice exists, instead find a minimum-cost choice that results in a draw. If neither a win nor a draw is possible, this must be indicated in the output.
Input
The input is given from Standard Input in the following format.
Each case is given in the following format.
are jtw7913's hole cards, and are the opponent's hole cards. are the flop cards. are the originally scheduled turn and river cards, respectively.
The costs on the last line correspond, in order, to ranks 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A.
Output
For each test case, print one line.
If jtw7913 can win, print the minimum total cost among all winning choices, together with a turn card and a river card attaining that cost, in the following format.
If there are multiple solutions, print any of them.
If no winning choice exists but a draw is possible, use the same format and print a minimum-cost choice resulting in a draw.
If neither a win nor a draw is possible, print -1.
Constraints
- .
- Every card is a length- string consisting of one rank character from
23456789TJQKA, followed by one suit character fromSHDC. - In each test case, are nine distinct physical cards.
- ().
Subtasks
Samples
In the first test case, keeping the scheduled KC and 3S gives the opponent three Kings. Replacing the turn with 4S while keeping 3S on the river leaves jtw7913 with a pair of Aces against the opponent's pair of Kings, for total cost .
In the second test case, no choice of turn and river can make jtw7913 win or draw.