Problem: Problem Statement

Texas hold 'em is one of the standard poker games, originated in Texas, United States. It is played with a standard deck of 52 cards, which has 4 suits (spades, hearts, diamonds and clubs) and 13 ranks (A, K, Q, J and 10-2), without jokers.

With betting aside, a game goes as described below.

At the beginning each player is dealt with 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 then one more community card called the river.

After the river, the game goes on 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: A, K, Q, J and 10 of the same suit. This is a special case of straight flush.
* Straight flush: Five cards in sequence (e.g. 7, 6, 5, 4 and 3) and 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: Just three cards of the same rank.
* Two pairs: Two cards of the same rank, and two other cards of another same rank.
* One pair: Just a pair of cards (two cards) of the same rank.
* High card: Any other hand.



For the purpose of a sequence, J, Q and K are treated as 11, 12 and 13 respectively. A can be seen as a rank either next above K or next below 2, thus both A-K-Q-J-10 and 5-4-3-2-A are possible (but not 3-2-A-K-Q or the likes).

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 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.
* High card: Compare all cards one by one.



The order of the ranks is A, K, Q, J, 10, 9, ..., 2, from the highest to the lowest, except for A next to 2 in a straight regarded as lower than 2. Note that there are exceptional cases where ties remain. Also note that the suits are not considered at all in tie-breaking.

Here are a few examples of comparison (note these are only intended for explanatory purpose; some combinations cannot happen in Texas Hold 'em):

* J-J-J-6-3 and K-K-Q-Q-8.




The former beats the latter since three of a kind is stronger than two pairs.

* J-J-J-6-3 and K-Q-8-8-8.




Since both are three of a kind, the triples are considered first, J and 8 in this case. J is higher, hence the former is a stronger hand. The remaining cards, 6-3 and K-Q, are not considered as the tie is already broken.

* Q-J-8-6-3 and Q-J-8-5-3.




Both are high cards, assuming hands not of a single suit (i.e. flush). The three highest-ranked cards Q-J-8 are the same, so the fourth highest are compared. The former is stronger since 6 is higher than 5.

* 9-9-Q-7-2 and 9-9-J-8-5.




Both are one pair, with the pair of the same rank (9). So the remaining cards, Q-7-2 and J-8-5, are compared from the highest to the lowest, and the former wins as Q is higher than J.

Now suppose you are playing a game of Texas Hold 'em with one opponent, and the hole cards and the flop have already been dealt. You are surprisingly telepathic and able to know the cards the opponent has. Your ability is not, however, as strong as you can predict which the turn and the river will be.

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 randomly from the remaining cards. You and the opponent always have to choose the hand strongest possible. Ties should be included in the calculation, i.e. should be counted as losses.



Input

The input consists of multiple datasets, each of which has the following format:


YourCard_1 YourCard_2
OpponentCard_1 OpponentCard_2
CommunityCard_1 CommunityCard_2 CommunityCard_3


Each dataset consists of three lines. The first and second lines contain the hole cards of yours and the opponent's 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: `S` (spades), `H` (hearts), `D` (diamonds) or `C` (clubs). The second one indicates the rank: `A`, `K`, `Q`, `J`, `T` (10) or `9`-`2`.

The end of the input is indicated by a line with `#`. This should not be processed.

Output

Print the probability in a line. The number may contain an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than 10^{-6}.

Examples

Input

SA SK
DA CA
SQ SJ ST
SA HA
D2 C3
H4 S5 DA
HA D9
H6 C9
H3 H4 H5
#


Output

1.00000000000000000000
0.34444444444444444198
0.63030303030303025391


Input

SA SK
DA CA
SQ SJ ST
SA HA
D2 C3
H4 S5 DA
HA D9
H6 C9
H3 H4 H5


Output

1.00000000000000000000
0.34444444444444444198
0.63030303030303025391

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

const char suit[] = "SHDC";

struct card{
	int rank, times;
	char suit;
	void print(){printf("%c%d ", suit, rank);}
	bool scan(){
		suit = 0;
		while(suit < 'A' || suit > 'Z'){
			suit = getchar();
			if(suit == '#') return false;
		}
		char ch = getchar();
		if(ch == 'A') rank = 14;
		else if(ch == 'T') rank = 10;
		else if(ch == 'J') rank = 11;
		else if(ch == 'Q') rank = 12;
		else if(ch == 'K') rank = 13;
		else rank = ch - '0';
		times = 1;
		return true;
	}
	
	bool friend operator < (card i, card j){return i.times == j.times ? i.rank > j.rank : i.times > j.times;}
	bool friend operator > (card i, card j){return i.times == j.times ? i.rank < j.rank : i.times < j.times;}
};

struct hand{
	card crds[5];
	bool flush, straight;
	int fir_kind, sec_kind;
	
	void scan(){for(int i = 0; i < 5; ++i) crds[i].scan();}
	void print(){for(int i = 0; i < 5; ++i) printf("%c%d ", crds[i].suit, crds[i].rank); puts("");}
	bool is_straight(){
		for(int i = 2; i < 5; ++i) if(crds[i].rank != crds[i-1].rank - 1) return false;
		if(crds[0].rank != 14) return crds[0].rank == crds[1].rank + 1;
		else{
			if(crds[1].rank == 13) return true;
			if(crds[4].rank == 2){
				for(int i = 1; i < 5; ++i) swap(crds[i], crds[i-1]);
				//print();
				return true;
			}
			return false;
		}
	}
	void pre(){
		int cnt[26];
		memset(cnt, 0, sizeof cnt);
		for(int i = 0; i < 5; ++i) ++cnt[crds[i].rank];
		fir_kind = sec_kind = 0;
		for(int i = 2; i <= 14; ++i){
			if(cnt[i] >= fir_kind) sec_kind = fir_kind, fir_kind = cnt[i];
			else sec_kind = max(sec_kind, cnt[i]);
			for(int j = 0; j < 5; ++j) if(crds[j].rank == i) crds[j].times = cnt[i];
		}
		flush = false;
		memset(cnt, 0, sizeof cnt);
		for(int i = 0; i < 5; ++i) ++cnt[crds[i].suit-'A'];
		for(int i = 0; i < 26; ++i) if(cnt[i] == 5) flush = true;
		sort(crds, crds + 5);
		straight = is_straight();
		//print();
	}
	bool is_royal_straight_flush(){
		if(!flush || !straight) return false;
		return crds[0].rank == 14;
	}
	bool is_four_of_a_kind(){
		if(fir_kind == 4) return true;
		else return false;
	}
	bool is_full_house(){
		if(fir_kind == 3 && sec_kind == 2) return true;
		else return false;
	}
	bool is_three_of_a_kind(){
		if(fir_kind == 3) return true;
		else return false;
	}
	bool is_two_pairs(){
		if(fir_kind == 2 && sec_kind == 2) return true;
		else return false;
	}
	bool is_one_pair(){
		if(fir_kind == 2) return true;
		else return false;
	}
	int spec(){
		if(is_royal_straight_flush()) return 9;
		if(straight && flush) return 8;
		if(is_four_of_a_kind()) return 7;
		if(is_full_house()) return 6;
		if(flush) return 5;
		if(straight) return 4;
		if(is_three_of_a_kind()) return 3;
		if(is_two_pairs()) return 2;
		if(is_one_pair()) return 1;
		return 0;
	}
};

int high_card(hand mine, hand yours){
	//mine.print();
	//yours.print();
	//puts("");
	//puts("high_card");
	for(int i = 0; i < 5; ++i){
		if(mine.crds[i] < yours.crds[i]) return 1; // actully >
		if(mine.crds[i] > yours.crds[i]) return -1;
	}
	return -1;
}

int showdown(hand mine, hand yours){
	mine.pre();
	yours.pre();
	//mine.print();
	//yours.print();
	int spec_mine = mine.spec();
	int spec_yours = yours.spec();
	//printf("%d %d\n", spec_mine, spec_yours);
	if(spec_mine > spec_yours) return 1;
	if(spec_mine < spec_yours) return -1;
	return high_card(mine, yours);
}

int cnt, win_cnt;
bool mine_found, yours_found;
hand mine, yours, mine_fir, yours_fir;
card pool_mine[7], pool_yours[7];
bool flag_mine[7], flag_yours[7], flag[26][20];

void dfs_yours(int pos, int beg){
	
	if(pos == 2){
		for(int i = 0, j = 0; i < 7; ++i){
			if(flag_yours[i]) continue;
			yours.crds[j++] = pool_yours[i];
		}
		if(!yours_found || showdown(yours, yours_fir) == 1) yours_fir = yours;
		yours_found = true;
		//puts("dfs_yours done");
		return;
	}
	for(int i = beg; i < 7; ++i){
		flag_yours[i] = true;
		dfs_yours(pos + 1, i + 1);
		flag_yours[i] = false;
	}
}

void dfs_mine(int pos, int beg){
	
	if(pos == 2){
		//puts("dfs_mine done");
		for(int i = 0, j = 0; i < 7; ++i){
			if(flag_mine[i]) continue;
			mine.crds[j++] = pool_mine[i];
		}
		if(!mine_found || showdown(mine, mine_fir) == 1) mine_fir = mine;
		mine_found = true;
		return;
	}
	for(int i = beg; i < 7; ++i){
		flag_mine[i] = true;
		dfs_mine(pos + 1, i + 1);
		flag_mine[i] = false;
	}
}

void dfs_turn_and_river(int pos){
	
	if(pos == 7){
		//puts("dfs_turn_and_river done");
		//for(int i = 0; i < 7; ++i) pool_mine[i].print(); puts("");
		//for(int i = 0; i < 7; ++i) pool_yours[i].print(); puts("");
		mine_found = false;
		yours_found = false;
		dfs_mine(0, 0);
		dfs_yours(0, 0);
		++cnt;
		if(showdown(mine_fir, yours_fir) == 1) ++win_cnt;
		//mine_fir.print();
		//yours_fir.print();
		//printf("%d\n", showdown(mine_fir, yours_fir));
		return;
	}
	for(int i = 0; i < 4; ++i){
		char s = suit[i];
		for(int j = 2; j <= 14; ++j){
			if(flag[s-'A'][j]) continue;
			flag[s-'A'][j] = true;
			pool_mine[pos].suit = s;
			pool_mine[pos].rank = j;
			pool_yours[pos] = pool_mine[pos];
			dfs_turn_and_river(pos + 1);
			flag[s-'A'][j] = false;
		}
	}
}

int main(){
	
	//freopen("poker.txt", "r", stdin);
	//freopen("poker.out", "w", stdout);
	
	while(true){
		
		if(!pool_mine[0].scan()) break;
		pool_mine[1].scan();
		for(int i = 0; i < 5; ++i) pool_yours[i].scan();
		for(int i = 2; i < 5; ++i) pool_mine[i] = pool_yours[i];
		memset(flag, 0, sizeof flag);
		for(int i = 0; i < 5; ++i) flag[pool_yours[i].suit-'A'][pool_yours[i].rank] = true;
		for(int i = 0; i < 5; ++i) flag[pool_mine[i].suit-'A'][pool_mine[i].rank] = true;
		//for(int i = 0; i < 5; ++i) pool_mine[i].print(); puts("");
		//for(int i = 0; i < 5; ++i) pool_yours[i].print(); puts("");
		cnt = win_cnt = 0;
		//puts("done");
		dfs_turn_and_river(5);
		//printf("%d %d\n", win_cnt, cnt);
		printf("%.15f\n", 1.00 * win_cnt / cnt);
		
		//mine_fir.print();
		//yours_fir.print(); 
	}

	return 0;
}