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
...(truncated)

Submitted solutions:

code_snippet: #include<set>
#include<cmath>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<numeric>
#include<vector>
#include<ctime>
#include<queue>
#include<list>
#include<map>
#define pi acos(-1)
#define INF 0x7fffffff
#define clr(x)  memset(x,0,sizeof(x));
#define clrto(x,siz,y)  for(int xx=0;xx<=siz;xx++)  x[xx]=y;
#define clrset(x,siz)  for(int xx=0;xx<=siz;xx++)  x[xx]=xx;
#define clrvec(x,siz) for(int xx=0;x<=siz;xx++)  x[xx].clear();
#define fop   freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define myprogram By_135678942570
#define clrcpy(x,siz,y)  for(int xx=0;xx<siz;xx++)  x[xx]=y[xx];
using namespace std;
int cd[1001];
map<int,int>mp[10];
int xx=0;
int vis[10011];
struct card
{
   int num;
   char s;
}C[100];
bool cmp(card a,card b)
{
    if(a.num<2&&b.num<2||a.num>=2&&b.num>=2)
       return a.num>b.num;
    return a.num<2;
}
void dfs(int cc,int now,int rst,int need,int cont,int sum,int add)
{
    if(rst==0)
    {
        int sz=mp[cc].size();
        mp[cc][sum]=sz+1+add;
     //   printf("%d %d %d %d %d\n",sum%13,sum%(13*13)/13,sum%(13*13*13)/(13*13),sum%(13*13*13*13)/(13*13*13),sum/(13*13*13*13));
     //   xx++;
        return;
    }
    for(int i=2;i<now;i++)
    {
        if(vis[i])
           continue;
        if(i==now-1&&need&&rst==1&&cont||need&&rst==1&&cont&&now==14&&i==5)
           continue;
        dfs(cc,i,rst-1,need,cont&&i==now-1||i==5&&now==14,sum*13+(i%13),add);
    }
}
int cntshun=10;
int cnttong=0;
int cnt=0;
int sum[10001];
void ini()
{
    for(int i=2;i<10;i++)
       cd[i+'0']=i;
    cd['T']=10;
    cd['A']=1;
    cd['J']=11;
    cd['Q']=12;
    cd['K']=0;
    clr(vis);
    for(int i=2;i<=14;i++)
        dfs(5,i,4,1,1,(i%13),0);
    cnt+=mp[5].size();
    sum[0]=cnt;
    for(int i=2;i<=14;i++)
    {
        vis[i]=1;
        dfs(4,15,3,0,0,13*(i%13)+(i%13),cnt);
        vis[i]=0;
    }
    cnt+=mp[4].size();
    sum[1]=cnt;
    for(int i=2;i<=14;i++)
    {
       vis[i]=1;
       for(int j=2;j<i;j++)
       {
          vis[j]=1;
          dfs(3,15,1,0,0,(13*(13*(13*(i%13)+(i%13))+(j%13))+(j%13)),cnt);
          vis[j]=0;
       }
       vis[i]=0;
    }
    cnt+=mp[3].size();
    sum[2]=cnt;
    for(int i=2;i<=14;i++)
    {
       vis[i]=1;
       dfs(6,15,2,0,0,13*(13*(i%13)+(i%13))+(i%13),cnt);
       vis[i]=0;
    }
    cnt+=mp[6].size();
    sum[3]=cnt;
    cnt+=14-5+1;
    sum[4]=cnt;
    cnt+=(cnttong=mp[5].size());
    sum[5]=cnt;
    for(int i=2;i<=14;i++)
      for(int j=2;j<=14;j++)
      if(i!=j)
      {
          int sz=mp[7].size();
          mp[7][13*(13*(13*(13*(i%13)+(i%13))+(i%13))+(j%13))+(j%13)]=cnt+1+sz;
      }
    cnt+=mp[7].size();
    sum[6]=cnt;
    for(int i=2;i<=14;i++)
    {
       vis[i]=1;
       dfs(2,15,1,0,0,13*(13*(13*(i%13)+(i%13))+(i%13))+(i%13),cnt);
       vis[i]=0;
    }
    cnt+=mp[2].size();
    sum[7]=cnt;
    cnt+=cntshun;
}
int getrank(char* s1, char* s2, char* s3, char* s4, char* s5)
{
     int flag1=1,flag2=1;
     int times[20]={0};
     int maxn=0;
     int doublepair=0;
     int maxi=0;
     int singlepair=0;
     for(int i=0;i<5;i++)
     {
         char a,aa[3];
         if(i == 0) aa[0] = s1[1], aa[1] = s1[0];
         if(i == 1) aa[0] = s2[1], aa[1] = s2[0];
         if(i == 2) aa[0] = s3[1], aa[1] = s3[0];
         if(i == 3) aa[0] = s4[1], aa[1] = s4[0];
         if(i == 4) aa[0] = s5[1], aa[1] = s5[0];
         a=aa[0],C[i].s=aa[1];
         //printf("%s\n", aa);
         C[i].num=cd[a];
         times[C[i].num]++;
         if(times[C[i].num]==2&&maxn==2)
            doublepair=1;
         else
         {
            if(maxn<times[C[i].num])
            {
                maxn=times[C[i].num];
                if(maxn==3&&maxi==C[i].num&&!doublepair)
                   singlepair=0;
                maxi=C[i].num;
            }
            if(times[C[i].num]==2)
               singlepair=1;
         }
         if(i!=0&&C[i].s!=C[0].s)
            flag2=0;
     }
     sort(C,C+5,cmp);
     if(C[0].num>=2&&C[0].num<5)
        flag1=0;
     for(int i=1;i<5;i++)
        if(!(C[i].num==5&&C[i-1].num==1)&&C[i].num!=(C[i-1].num-1+13)%13)
           flag1=0;
     if(flag1&&flag2)
     {
         if(C[0].num==1&&C[4].num==2)
            return (sum[7]+1);
         else if(C[0].num<2)
            return (sum[7]+9+C[0].num);
         else return (sum[7]+C[0].num-4);
     }
     else if(maxn==4)
     {
         int temp;
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
               temp=C[i].num;
         return (mp[2][13*(13*(13*(13*maxi+maxi)+maxi)+maxi)+temp]);
     }
     else if(maxn==3&&singlepair)
     {
         int temp;
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
               temp=C[i].num;
         return (mp[7][13*(13*(13*(13*maxi+maxi)+maxi)+temp)+temp]);
     }
     else if(flag2)
     {
         return (sum[4]+mp[5][13*(13*(13*(13*C[0].num+C[1].num)+C[2].num)+C[3].num)+C[4].num]);
     }
     else if(flag1)
     {
         if(C[0].num==1&&C[4].num==2)
           return (sum[3]+1);
         else if(C[0].num<2)
            return (sum[3]+9+C[0].num);
         else return (sum[3]+C[0].num-4);
     }
     else if(maxn==3)
     {
         int cnt=0;
         int a[2]={0};
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
              a[cnt++]=C[i].num;
         return (mp[6][13*(13*(13*(13*maxi+maxi)+maxi)+a[0])+a[1]]);
     }
     else if(doublepair)
     {
         int a,b;
         int temp;
         for(int i=0;i<5;i++)
            if(times[C[i].num]==2)
               b=C[i].num;
            else temp=C[i].num;
         for(int i=4;i>=0;i--)
            if(times[C[i].num]==2)
               a=C[i].num;
         return (mp[3][13*(13*(13*(13*a+a)+b)+b)+temp]);
     }
     else if(singlepair)
     {
         int cnt=0;
         int a[3]={0};
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
               a[cnt++]=C[i].num;
         return (mp[4][13*(13*(13*(13*maxi+maxi)+a[0])+a[1])+a[2]]);
     }
     else
         return (mp[5][13*(13*(13*(13*C[0].num+C[1].num)+C[2].num)+C[3].num)+C[4].num]);
}
map<string, int>vvv;
char getcolor(int p)
{
    if(p == 0)
        return 'S';
    if(p == 1)
        return 'H';
    if(p == 2)
        return 'D';
    return 'C';
}
char getid(int p)
{
    if(p == 1)
        return 'A';
    if(p == 0)
        return 'K';
    if(p < 10)
        return p + '0';
    if(p == 10)
        return 'T';
    if(p == 11)
        return 'J';
    if(p == 12)
        return 'Q';
}
int main()
{
    ini();
    //printf("%d\n", getrank("H2", "H3", "H4", "H5", "H6"));
    while(1)
    {
        vvv.clear();
        char m1[5], m2[5];
        scanf("%s", m1);
        if(m1[0] == '#')
            break;
        scanf("%s", m2);
        vvv[m1] = 1, vvv[m2] = 1;
        char o1[5], o2[5];
        scanf("%s%s", o1, o2);
        vvv[o1] = 1, vvv[o2] = 1;
        char r[5][5] = {0};
        scanf("%s%s%s", r[0], r[1], r[2]);
        vvv[r[0]] = 1;
        vvv[r[1]] = 1;
        vvv[r[2]] = 1;
        int all = 0;
        int ct = 0;
        for(int i = 0; i < 4; i++)
            for(int j = 0; j < 13; j++)
            {
                r[3][0] = getcolor(i);
                r[3][1] = getid(j);
                if(vvv[r[3]] == 0)
                {
                    vvv[r[3]] = 1;
                    for(int i1 = 0; i1 < 4; i1++)
                        for(int j1 = 0; j1 < 13; j1++)
                        {
                            r[4][0] = getcolor(i1);
                            r[4][1] = getid(j1);
                            if(vvv[r[4]] == 0)
                            {
                                int maxn1 = 0;
                                int maxn2 = 0;
                                for(int a = 0; a < 5; a++)
                                    for(int b = a + 1; b < 5; b++)
                                        for(int c = b + 1; c < 5; c++)
                                        {
                                            int r1 = getrank(m1, m2, r[a], r[b], r[c]);
                                            int r2 = getrank(o1, o2, r[a], r[b], r[c]);
                                            maxn1 = max(maxn1, r1);
                                            maxn2 = max(maxn2, r2);
                                        }
                                for(int a = 0; a < 5; a++)
                                    for(int b = a + 1; b < 5; b++)
                                        for(int c = b + 1; c < 5; c++)
                                            for(int d = c + 1; d < 5; d++)
                                            {
                                                int r1 = getrank(m1, r[d], r[a], r[b], r[c]);
                                                int r2 = getrank(o1, r[d], r[a], r[b], r[c]);
                                                maxn1 = max(maxn1, r1);
                                                maxn2 = max(maxn2, r2);
                                                r1 = getrank(m2, r[d], r[a], r[b], r[c]);
                                                r2 = getrank(o2, r[d], r[a], r[b], r[c]);
                                                maxn1 = max(maxn1, r1);
                                                maxn2 = max(maxn2, r2);
                                            }
                                maxn1 = max(maxn1, getrank(r[0], r[1], r[2], r[3], r[4]));
                                maxn2 = max(maxn2, getrank(r[0], r[1], r[2], r[3], r[4]));
                                all++;
                                if(maxn1 > maxn2)
                                {
                                    ct++;
                                    //printf("%s %s\n", r[3], r[4]);
                                    //system("pause");
                                }
                                //else printf("%s %s\n", r[3], r[4]);
                            }
                        }
                }
            }
        printf("%.20f\n", ct * 1.0 / all);
    }
}
accuracy: 1
time_ms: 330
memory_kb: 3892
final_rank: 14

code_snippet: #include<set>
#include<cmath>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<numeric>
#include<vector>
#include<ctime>
#include<queue>
#include<list>
#include<map>
#define pi acos(-1)
#define INF 0x7fffffff
#define clr(x)  memset(x,0,sizeof(x));
#define clrto(x,siz,y)  for(int xx=0;xx<=siz;xx++)  x[xx]=y;
#define clrset(x,siz)  for(int xx=0;xx<=siz;xx++)  x[xx]=xx;
#define clrvec(x,siz) for(int xx=0;x<=siz;xx++)  x[xx].clear();
#define fop   freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define myprogram By_135678942570
#define clrcpy(x,siz,y)  for(int xx=0;xx<siz;xx++)  x[xx]=y[xx];
using namespace std;
int cd[1001];
map<int,int>mp[10];
int xx=0;
int vis[10011];
struct card
{
   int num;
   char s;
}C[100];
bool cmp(card a,card b)
{
    if(a.num<2&&b.num<2||a.num>=2&&b.num>=2)
       return a.num>b.num;
    return a.num<2;
}
void dfs(int cc,int now,int rst,int need,int cont,int sum,int add)
{
    if(rst==0)
    {
        int sz=mp[cc].size();
        mp[cc][sum]=sz+1+add;
     //   printf("%d %d %d %d %d\n",sum%13,sum%(13*13)/13,sum%(13*13*13)/(13*13),sum%(13*13*13*13)/(13*13*13),sum/(13*13*13*13));
     //   xx++;
        return;
    }
    for(int i=2;i<now;i++)
    {
        if(vis[i])
           continue;
        if(i==now-1&&need&&rst==1&&cont||need&&rst==1&&cont&&now==14&&i==5)
           continue;
        dfs(cc,i,rst-1,need,cont&&i==now-1||i==5&&now==14,sum*13+(i%13),add);
    }
}
int cntshun=10;
int cnttong=0;
int cnt=0;
int sum[10001];
void ini()
{
    for(int i=2;i<10;i++)
       cd[i+'0']=i;
    cd['T']=10;
    cd['A']=1;
    cd['J']=11;
    cd['Q']=12;
    cd['K']=0;
    clr(vis);
    for(int i=2;i<=14;i++)
        dfs(5,i,4,1,1,(i%13),0);
    cnt+=mp[5].size();
    sum[0]=cnt;
    for(int i=2;i<=14;i++)
    {
        vis[i]=1;
        dfs(4,15,3,0,0,13*(i%13)+(i%13),cnt);
        vis[i]=0;
    }
    cnt+=mp[4].size();
    sum[1]=cnt;
    for(int i=2;i<=14;i++)
    {
       vis[i]=1;
       for(int j=2;j<i;j++)
       {
          vis[j]=1;
          dfs(3,15,1,0,0,(13*(13*(13*(i%13)+(i%13))+(j%13))+(j%13)),cnt);
          vis[j]=0;
       }
       vis[i]=0;
    }
    cnt+=mp[3].size();
    sum[2]=cnt;
    for(int i=2;i<=14;i++)
    {
       vis[i]=1;
       dfs(6,15,2,0,0,13*(13*(i%13)+(i%13))+(i%13),cnt);
       vis[i]=0;
    }
    cnt+=mp[6].size();
    sum[3]=cnt;
    cnt+=14-5+1;
    sum[4]=cnt;
    cnt+=(cnttong=mp[5].size());
    sum[5]=cnt;
    for(int i=2;i<=14;i++)
      for(int j=2;j<=14;j++)
      if(i!=j)
      {
          int sz=mp[7].size();
          mp[7][13*(13*(13*(13*(i%13)+(i%13))+(i%13))+(j%13))+(j%13)]=cnt+1+sz;
      }
    cnt+=mp[7].size();
    sum[6]=cnt;
    for(int i=2;i<=14;i++)
    {
       vis[i]=1;
       dfs(2,15,1,0,0,13*(13*(13*(i%13)+(i%13))+(i%13))+(i%13),cnt);
       vis[i]=0;
    }
    cnt+=mp[2].size();
    sum[7]=cnt;
    cnt+=cntshun;
}
int getrank(char* s1, char* s2, char* s3, char* s4, char* s5)
{
     int flag1=1,flag2=1;
     int times[20]={0};
     int maxn=0;
     int doublepair=0;
     int maxi=0;
     int singlepair=0;
     for(int i=0;i<5;i++)
     {
         char a,aa[3];
         if(i == 0) aa[0] = s1[1], aa[1] = s1[0];
         if(i == 1) aa[0] = s2[1], aa[1] = s2[0];
         if(i == 2) aa[0] = s3[1], aa[1] = s3[0];
         if(i == 3) aa[0] = s4[1], aa[1] = s4[0];
         if(i == 4) aa[0] = s5[1], aa[1] = s5[0];
         a=aa[0],C[i].s=aa[1];
         //printf("%s\n", aa);
         C[i].num=cd[a];
         times[C[i].num]++;
         if(times[C[i].num]==2&&maxn==2)
            doublepair=1;
         else
         {
            if(maxn<times[C[i].num])
            {
                maxn=times[C[i].num];
                if(maxn==3&&maxi==C[i].num&&!doublepair)
                   singlepair=0;
                maxi=C[i].num;
            }
            if(times[C[i].num]==2)
               singlepair=1;
         }
         if(i!=0&&C[i].s!=C[0].s)
            flag2=0;
     }
     sort(C,C+5,cmp);
     if(C[0].num>=2&&C[0].num<5)
        flag1=0;
     for(int i=1;i<5;i++)
        if(!(C[i].num==5&&C[i-1].num==1)&&C[i].num!=(C[i-1].num-1+13)%13)
           flag1=0;
     if(flag1&&flag2)
     {
         if(C[0].num==1&&C[4].num==2)
            return (sum[7]+1);
         else if(C[0].num<2)
            return (sum[7]+9+C[0].num);
         else return (sum[7]+C[0].num-4);
     }
     else if(maxn==4)
     {
         int temp;
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
               temp=C[i].num;
         return (mp[2][13*(13*(13*(13*maxi+maxi)+maxi)+maxi)+temp]);
     }
     else if(maxn==3&&singlepair)
     {
         int temp;
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
               temp=C[i].num;
         return (mp[7][13*(13*(13*(13*maxi+maxi)+maxi)+temp)+temp]);
     }
     else if(flag2)
     {
         return (sum[4]+mp[5][13*(13*(13*(13*C[0].num+C[1].num)+C[2].num)+C[3].num)+C[4].num]);
     }
     else if(flag1)
     {
         if(C[0].num==1&&C[4].num==2)
           return (sum[3]+1);
         else if(C[0].num<2)
            return (sum[3]+9+C[0].num);
         else return (sum[3]+C[0].num-4);
     }
     else if(maxn==3)
     {
         int cnt=0;
         int a[2]={0};
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
              a[cnt++]=C[i].num;
         return (mp[6][13*(13*(13*(13*maxi+maxi)+maxi)+a[0])+a[1]]);
     }
     else if(doublepair)
     {
         int a,b;
         int temp;
         for(int i=0;i<5;i++)
            if(times[C[i].num]==2)
               b=C[i].num;
            else temp=C[i].num;
         for(int i=4;i>=0;i--)
            if(times[C[i].num]==2)
               a=C[i].num;
         return (mp[3][13*(13*(13*(13*a+a)+b)+b)+temp]);
     }
     else if(singlepair)
     {
         int cnt=0;
         int a[3]={0};
         for(int i=0;i<5;i++)
            if(maxi!=C[i].num)
               a[cnt++]=C[i].num;
         return (mp[4][13*(13*(13*(13*maxi+maxi)+a[0])+a[1])+a[2]]);
     }
     else
         return (mp[5][13*(13*(13*(13*C[0].num+C[1].num)+C[2].num)+C[3].num)+C[4].num]);
}
map<string, int>vvv;
char getcolor(int p)
{
    if(p == 0)
        return 'S';
    if(p == 1)
        return 'H';
    if(p == 2)
        return 'D';
    return 'C';
}
char getid(int p)
{
    if(p == 1)
        return 'A';
    if(p == 0)
        return 'K';
    if(p < 10)
        return p + '0';
    if(p == 10)
        return 'T';
    if(p == 11)
        return 'J';
    if(p == 12)
        return 'Q';
}
int main()
{
    ini();
    //printf("%d\n", getrank("H2", "H3", "H4", "H5", "H6"));
    while(1)
    {
        vvv.clear();
        char m1[5], m2[5];
        scanf("%s", m1);
        if(m1[0] == '#')
            break;
        scanf("%s", m2);
        vvv[m1] = 1, vvv[m2] = 1;
        char o1[5], o2[5];
        scanf("%s%s", o1, o2);
        vvv[o1] = 1, vvv[o2] = 1;
        char r[5][5] = {0};
        scanf("%s%s%s", r[0], r[1], r[2]);
        vvv[r[0]] = 1;
        vvv[r[1]] = 1;
        vvv[r[2]] = 1;
        int all = 0;
        int ct = 0;
        for(int i = 0; i < 4; i++)
            for(int j = 0; j < 13; j++)
            {
                r[3][0] = getcolor(i);
                r[3][1] = getid(j);
                if(vvv[r[3]] == 0)
                {
                    vvv[r[3]] = 1;
                    for(int i1 = 0; i1 < 4; i1++)
                        for(int j1 = 0; j1 < 13; j1++)
                        {
                            r[4][0] = getcolor(i1);
                            r[4][1] = getid(j1);
                            if(vvv[r[4]] == 0)
                            {
                                int maxn1 = 0;
                                int maxn2 = 0;
                                for(int a = 0; a < 5; a++)
                                    for(int b = a + 1; b < 5; b++)
                                        for(int c = b + 1; c < 5; c++)
                                        {
                                            int r1 = getrank(m1, m2, r[a], r[b], r[c]);
                                            int r2 = getrank(o1, o2, r[a], r[b], r[c]);
                                            maxn1 = max(maxn1, r1);
                                            maxn2 = max(maxn2, r2);
                                        }
                                for(int a = 0; a < 5; a++)
                                    for(int b = a + 1; b < 5; b++)
                                        for(int c = b + 1; c < 5; c++)
                                            for(int d = c + 1; d < 5; d++)
                                            {
                                                int r1 = getrank(m1, r[d], r[a], r[b], r[c]);
                                                int r2 = getrank(o1, r[d], r[a], r[b], r[c]);
                                                maxn1 = max(maxn1, r1);
                                                maxn2 = max(maxn2, r2);
                                                r1 = getrank(m2, r[d], r[a], r[b], r[c]);
                                                r2 = getrank(o2, r[d], r[a], r[b], r[c]);
                                                maxn1 = max(maxn1, r1);
                                                maxn2 = max(maxn2, r2);
                                            }
                                maxn1 = max(maxn1, getrank(r[0], r[1], r[2], r[3], r[4]));
                                maxn2 = max(maxn2, getrank(r[0], r[1], r[2], r[3], r[4]));
                                all++;
                                if(maxn1 > maxn2)
                                {
                                    ct++;
                                    //printf("%s %s\n", r[3], r[4]);
                                    //system("pause");
                                }
                                //else printf("%s %s\n", r[3], r[4]);
                            }
                        }
                    vvv[r[3]] = 0;
                }
            }
        printf("%.20f\n", ct * 1.0 / all);
    }
}
accuracy: 1
time_ms: 640
memory_kb: 3740
final_rank: 12

code_snippet: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <map>
using namespace std;

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double ld;
typedef pair<int,int> pii;
#define ui(n) ((unsigned int)(n))
#define ll(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)
const int INF=1e9+7;
const LL LINF=1e18;
#define PI 3.1415926535897932384626433832795028841971
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define mod 1000000007
#define sz(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repa(i,a,n) for(int i=a;i<n;i++)
#define repa1(i,a,n) for(int i=a;i<=n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repd1(i,n) for(int i=n;i>=1;i--)
#define FOR(i,a,n,step) for(int i=a;i<n;i+=step)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define sqr(x) ((x)*(x))
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define file(filename,name) fstream name(filename,ios::in|ios::out)
#define fs first
#define sc second
#define PC(x) putchar(x)
#define GC(x) x=getchar()
#define Endl PC('\n')
#define SF scanf
#define PF printf

map<int,int> suit,Rank;
int ans;
LL hashes[20];
bool used[60];

struct Card
{
	int suit,Rank,hsh;
	
	bool operator < (Card card) const
	{
		return Rank>card.Rank;
	}
	
	Card() {}
	Card(int hah)
	{
		hsh=hah;
		suit=hah/13;
		Rank=hah%13;
	}
} card1[10],card2[10],card3[10],card4[10];

inline void INIT()
{
	suit['S']=0;
	suit['H']=1;
	suit['D']=2;
	suit['C']=3;
	
	Rank['2']=0;
	Rank['3']=1;
	Rank['4']=2;
	Rank['5']=3;
	Rank['6']=4;
	Rank['7']=5;
	Rank['8']=6;
	Rank['9']=7;
	Rank['T']=8;
	Rank['J']=9;
	Rank['Q']=10;
	Rank['K']=11;
	Rank['A']=12;
	
	hashes[0]=1ll;
	rep1(i,15) hashes[i]=hashes[i-1]*14;
}

inline void Read(Card &card)
{
	string s;cin>>s;
	if(s=="#") exit(0);
	
	card=Card(suit[s[0]]*13+Rank[s[1]]);
}

inline LL calc(Card card[])
{
	sort(card+1,card+6);
	rep1(i,5) card[i].Rank++;
	
	//(Royal) Straight flush
	if(card[1].suit==card[2].suit&&card[2].suit==card[3].suit&&card[3].suit==card[4].suit&&card[4].suit==card[5].suit)
	{
		if(card[1].Rank-card[2].Rank==1&&card[2].Rank-card[3].Rank==1&&card[3].Rank-card[4].Rank==1&&card[4].Rank-card[5].Rank==1) return hashes[15]*card[1].Rank;
		
		//Special Straight flush: A,2,3,4,5 -> 13,1,2,3,4
		if(card[1].Rank==13&&card[2].Rank==4&&card[3].Rank==3&&card[4].Rank==2&&card[5].Rank==1) return hashes[15]*card[2].Rank;
	}
	
	//Four of a kind
	if(card[2].Rank==card[3].Rank&&card[3].Rank==card[4].Rank)
	{
		if(card[1].Rank==card[2].Rank) return hashes[14]*card[2].Rank+hashes[0]*card[5].Rank;
		if(card[5].Rank==card[2].Rank) return hashes[14]*card[2].Rank+hashes[0]*card[1].Rank;
	}
	
	//Full house
	if(card[1].Rank==card[2].Rank&&card[4].Rank==card[5].Rank)
	{
		if(card[3].Rank==card[1].Rank) return hashes[13]*card[1].Rank+hashes[0]*card[4].Rank;
		if(card[3].Rank==card[4].Rank) return hashes[13]*card[4].Rank+hashes[0]*card[1].Rank;
	}
	
	//Flush
	if(card[1].suit==card[2].suit&&card[2].suit==card[3].suit&&card[3].suit==card[4].suit&&card[4].suit==card[5].suit) return hashes[12]*card[1].Rank+hashes[3]*card[2].Rank+hashes[2]*card[3].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	
	//Straight
	if(card[1].Rank-card[2].Rank==1&&card[2].Rank-card[3].Rank==1&&card[3].Rank-card[4].Rank==1&&card[4].Rank-card[5].Rank==1) return hashes[11]*card[1].Rank;
	//Special Straight: A,2,3,4,5 -> 13,1,2,3,4
	if(card[1].Rank==13&&card[2].Rank==4&&card[3].Rank==3&&card[4].Rank==2&&card[5].Rank==1) return hashes[11]*card[2].Rank;
	
	//Three of a kind
	if(card[1].Rank==card[2].Rank&&card[2].Rank==card[3].Rank) return hashes[10]*card[1].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	if(card[2].Rank==card[3].Rank&&card[3].Rank==card[4].Rank) return hashes[10]*card[2].Rank+hashes[1]*card[1].Rank+hashes[0]*card[5].Rank;
	if(card[3].Rank==card[4].Rank&&card[4].Rank==card[5].Rank) return hashes[10]*card[3].Rank+hashes[1]*card[1].Rank+hashes[0]*card[2].Rank;
	
	//Two pairs
	if(card[1].Rank==card[2].Rank&&card[3].Rank==card[4].Rank) return hashes[9]*card[1].Rank+hashes[1]*card[3].Rank+hashes[0]*card[5].Rank;
	if(card[1].Rank==card[2].Rank&&card[4].Rank==card[5].Rank) return hashes[9]*card[1].Rank+hashes[1]*card[4].Rank+hashes[0]*card[3].Rank;
	if(card[2].Rank==card[3].Rank&&card[4].Rank==card[5].Rank) return hashes[9]*card[2].Rank+hashes[1]*card[4].Rank+hashes[0]*card[1].Rank;
	
	//One pair
	if(card[1].Rank==card[2].Rank) return hashes[8]*card[1].Rank+hashes[2]*card[3].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	if(card[2].Rank==card[3].Rank) return hashes[8]*card[2].Rank+hashes[2]*card[1].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	if(card[3].Rank==card[4].Rank) return hashes[8]*card[3].Rank+hashes[2]*card[1].Rank+hashes[1]*card[2].Rank+hashes[0]*card[5].Rank;
	if(card[4].Rank==card[5].Rank) return hashes[8]*card[4].Rank+hashes[2]*card[1].Rank+hashes[1]*card[2].Rank+hashes[0]*card[3].Rank;
	
	//High card
	return hashes[4]*card[1].Rank+hashes[3]*card[2].Rank+hashes[2]*card[3].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
}

inline int win()
{
	LL res1=0,res2=0;
	
	rep1(i,6) repa1(j,i+1,7)
	{
		int len=0;
		rep1(k,7) if(k!=i&&k!=j)
		{
			len++;
			card3[len]=card1[k];
			card4[len]=card2[k];
		}
		
		res1=max(res1,calc(card3));
		res2=max(res2,calc(card4));
	}
	
	return res1>res2;
}

int main()
{
	INIT();
	
	while(1)
	{
		ans=0;
		MC(used);
		
		Read(card1[1]);Read(card1[2]);
		Read(card2[1]);Read(card2[2]);
		
		Read(card1[3]);Read(card1[4]);Read(card1[5]);
		card2[3]=card1[3];card2[4]=card1[4];card2[5]=card1[5];
		
		used[card1[1].hsh]=used[card1[2].hsh]=used[card2[1].hsh]=used[card2[2].hsh]=used[card1[3].hsh]=used[card1[4].hsh]=used[card1[5].hsh]=1;
		
		rep(i,52) if(!used[i]) repa(j,i+1,52) if(!used[j]&&i!=j)
		{
			card1[6]=card2[6]=Card(i);
			card1[7]=card2[7]=Card(j);
			
			ans+=win();
		}
		
		PF("%.20lf\n",ans/ld(990));
	}

	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3412
final_rank: 2

code_snippet: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <unordered_map>
using namespace std;

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double ld;
typedef pair<int,int> pii;
#define ui(n) ((unsigned int)(n))
#define ll(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)
const int INF=1e9+7;
const LL LINF=1e18;
#define PI 3.1415926535897932384626433832795028841971
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define mod 1000000007
#define sz(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repa(i,a,n) for(int i=a;i<n;i++)
#define repa1(i,a,n) for(int i=a;i<=n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repd1(i,n) for(int i=n;i>=1;i--)
#define FOR(i,a,n,step) for(int i=a;i<n;i+=step)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define sqr(x) ((x)*(x))
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define file(filename,name) fstream name(filename,ios::in|ios::out)
#define fs first
#define sc second
#define PC(x) putchar(x)
#define GC(x) x=getchar()
#define Endl PC('\n')
#define SF scanf
#define PF printf

unordered_map<int,int> suit,Rank;
int ans;
LL hashes[20];
bool used[60];

struct Card
{
	int suit,Rank,hsh;
	
	bool operator < (Card card) const
	{
		return Rank>card.Rank;
	}
	
	Card() {}
	Card(int hah)
	{
		hsh=hah;
		suit=hah/13;
		Rank=hah%13;
	}
} card1[10],card2[10],card3[10],card4[10];

inline void INIT()
{
	suit['S']=0;
	suit['H']=1;
	suit['D']=2;
	suit['C']=3;
	
	Rank['2']=0;
	Rank['3']=1;
	Rank['4']=2;
	Rank['5']=3;
	Rank['6']=4;
	Rank['7']=5;
	Rank['8']=6;
	Rank['9']=7;
	Rank['T']=8;
	Rank['J']=9;
	Rank['Q']=10;
	Rank['K']=11;
	Rank['A']=12;
	
	hashes[0]=1ll;
	rep1(i,15) hashes[i]=hashes[i-1]*14;
}

inline void Read(Card &card)
{
	string s;cin>>s;
	if(s=="#") exit(0);
	
	card=Card(suit[s[0]]*13+Rank[s[1]]);
}

inline LL calc(Card card[])
{
	sort(card+1,card+6);
	rep1(i,5) card[i].Rank++;
	
	//(Royal) Straight flush
	if(card[1].suit==card[2].suit&&card[2].suit==card[3].suit&&card[3].suit==card[4].suit&&card[4].suit==card[5].suit)
	{
		if(card[1].Rank-card[2].Rank==1&&card[2].Rank-card[3].Rank==1&&card[3].Rank-card[4].Rank==1&&card[4].Rank-card[5].Rank==1) return hashes[15]*card[1].Rank;
		
		//Special Straight flush: A,2,3,4,5 -> 13,1,2,3,4
		if(card[1].Rank==13&&card[2].Rank==4&&card[3].Rank==3&&card[4].Rank==2&&card[5].Rank==1) return hashes[15]*card[2].Rank;
	}
	
	//Four of a kind
	if(card[2].Rank==card[3].Rank&&card[3].Rank==card[4].Rank)
	{
		if(card[1].Rank==card[2].Rank) return hashes[14]*card[2].Rank+hashes[0]*card[5].Rank;
		if(card[5].Rank==card[2].Rank) return hashes[14]*card[2].Rank+hashes[0]*card[1].Rank;
	}
	
	//Full house
	if(card[1].Rank==card[2].Rank&&card[4].Rank==card[5].Rank)
	{
		if(card[3].Rank==card[1].Rank) return hashes[13]*card[1].Rank+hashes[0]*card[4].Rank;
		if(card[3].Rank==card[4].Rank) return hashes[13]*card[4].Rank+hashes[0]*card[1].Rank;
	}
	
	//Flush
	if(card[1].suit==card[2].suit&&card[2].suit==card[3].suit&&card[3].suit==card[4].suit&&card[4].suit==card[5].suit) return hashes[12]*card[1].Rank+hashes[3]*card[2].Rank+hashes[2]*card[3].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	
	//Straight
	if(card[1].Rank-card[2].Rank==1&&card[2].Rank-card[3].Rank==1&&card[3].Rank-card[4].Rank==1&&card[4].Rank-card[5].Rank==1) return hashes[11]*card[1].Rank;
	//Special Straight: A,2,3,4,5 -> 13,1,2,3,4
	if(card[1].Rank==13&&card[2].Rank==4&&card[3].Rank==3&&card[4].Rank==2&&card[5].Rank==1) return hashes[11]*card[2].Rank;
	
	//Three of a kind
	if(card[1].Rank==card[2].Rank&&card[2].Rank==card[3].Rank) return hashes[10]*card[1].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	if(card[2].Rank==card[3].Rank&&card[3].Rank==card[4].Rank) return hashes[10]*card[2].Rank+hashes[1]*card[1].Rank+hashes[0]*card[5].Rank;
	if(card[3].Rank==card[4].Rank&&card[4].Rank==card[5].Rank) return hashes[10]*card[3].Rank+hashes[1]*card[1].Rank+hashes[0]*card[2].Rank;
	
	//Two pairs
	if(card[1].Rank==card[2].Rank&&card[3].Rank==card[4].Rank) return hashes[9]*card[1].Rank+hashes[1]*card[3].Rank+hashes[0]*card[5].Rank;
	if(card[1].Rank==card[2].Rank&&card[4].Rank==card[5].Rank) return hashes[9]*card[1].Rank+hashes[1]*card[4].Rank+hashes[0]*card[3].Rank;
	if(card[2].Rank==card[3].Rank&&card[4].Rank==card[5].Rank) return hashes[9]*card[2].Rank+hashes[1]*card[4].Rank+hashes[0]*card[1].Rank;
	
	//One pair
	if(card[1].Rank==card[2].Rank) return hashes[8]*card[1].Rank+hashes[2]*card[3].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	if(card[2].Rank==card[3].Rank) return hashes[8]*card[2].Rank+hashes[2]*card[1].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
	if(card[3].Rank==card[4].Rank) return hashes[8]*card[3].Rank+hashes[2]*card[1].Rank+hashes[1]*card[2].Rank+hashes[0]*card[5].Rank;
	if(card[4].Rank==card[5].Rank) return hashes[8]*card[4].Rank+hashes[2]*card[1].Rank+hashes[1]*card[2].Rank+hashes[0]*card[3].Rank;
	
	//High card
	return hashes[4]*card[1].Rank+hashes[3]*card[2].Rank+hashes[2]*card[3].Rank+hashes[1]*card[4].Rank+hashes[0]*card[5].Rank;
}

inline int win()
{
	LL res1=0,res2=0;
	
	rep1(i,6) repa1(j,i+1,7)
	{
		int len=0;
		rep1(k,7) if(k!=i&&k!=j)
		{
			len++;
			card3[len]=card1[k];
			card4[len]=card2[k];
		}
		
		res1=max(res1,calc(card3));
		res2=max(res2,calc(card4));
	}
	
	return res1>res2;
}

int main()
{
	INIT();
	
	while(1)
	{
		ans=0;
		MC(used);
		
		Read(card1[1]);Read(card1[2]);
		Read(card2[1]);Read(card2[2]);
		
		Read(card1[3]);Read(card1[4]);Read(card1[5]);
		card2[3]=card1[3];card2[4]=card1[4];card2[5]=card1[5];
		
		used[card1[1].hsh]=used[card1[2].hsh]=used[card2[1].hsh]=used[card2[2].hsh]=used[card1[3].hsh]=used[card1[4].hsh]=used[card1[5].hsh]=1;
		
		rep(i,52) if(!used[i]) repa(j,i+1,52) if(!used[j]&&i!=j)
		{
			card1[6]=card2[6]=Card(i);
			card1[7]=card2[7]=Card(j);
			
			ans+=win();
		}
		
		PF("%.20lf\n",ans/ld(990));
	}

	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3400
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<ll(n); i++)
template<class A, class B> void chmax(A& a, const B& b){ if(a < b) a = b; }

struct Card{ ll n; ll d; };

using Hand = array<ll, 6>;

Hand evalHand(array<Card, 5> x){
    bool isFlush = true;
    rep(i,4) if(x[i].d != x[i+1].d) isFlush = false;
    bool isStraight = true;
    rep(i,4) if(x[i].n + 1 != x[i+1].n) isStraight = false;
    ll ad = 0;
    rep(i,4) if(x[i].n == x[i+1].n) ad |= 1 << i;
    ll e = x[0].n, d = x[1].n, c = x[2].n, b = x[3].n, a = x[4].n;
    bool is12345 = a == 14 && b == 5 && c == 4 && d == 3 && e == 2;

    if(isStraight && isFlush && a == 14) return { 100, 0, 0, 0, 0, 0 };
    if(isStraight && isFlush) return { 99, a, 0, 0, 0, 0 };
    if(is12345 && isFlush) return { 99, 5, 0, 0, 0, 0 };
    if(isStraight) return { 4, a, 0, 0, 0, 0 };
    if(is12345) return { 4, 5, 0, 0, 0, 0 };
    if(isFlush) return { 5, a, b, c, d, e };

    if(ad == 0b1000) return { 1, a, c, d, e, 0 };
    if(ad == 0b0100) return { 1, b, a, d, e, 0 };
    if(ad == 0b0010) return { 1, c, a, b, e, 0 };
    if(ad == 0b0001) return { 1, d, a, b, c, 0 };
    
    if(ad == 0b1010) return { 2, a, c, e, 0, 0 };
    if(ad == 0b1001) return { 2, a, d, c, 0, 0 };
    if(ad == 0b0101) return { 2, b, d, a, 0, 0 };

    if(ad == 0b1100) return { 3, a, d, e, 0, 0 };
    if(ad == 0b0110) return { 3, b, a, e, 0, 0 };
    if(ad == 0b0011) return { 3, c, a, b, 0, 0 };
    
    if(ad == 0b1101) return { 7, a, e, 0, 0, 0 };
    if(ad == 0b1011) return { 7, c, a, 0, 0, 0 };
    
    if(ad == 0b1110) return { 8, a, e, 0, 0, 0 };
    if(ad == 0b0111) return { 8, b, a, 0, 0, 0 };

    return { 0, a, b, c, d, e };
}

Hand evalHand7(array<Card, 7> x){
    Hand h = {0,0,0,0,0,0};
    sort(x.begin(), x.end(), [&](Card& l, Card& r){ return l.n < r.n; });
    chmax(h, evalHand({x[0], x[1], x[2], x[3], x[4]}));
    chmax(h, evalHand({x[0], x[1], x[2], x[3], x[5]}));
    chmax(h, evalHand({x[0], x[1], x[2], x[3], x[6]}));
    chmax(h, evalHand({x[0], x[1], x[2], x[4], x[5]}));
    chmax(h, evalHand({x[0], x[1], x[2], x[4], x[6]}));
    chmax(h, evalHand({x[0], x[1], x[2], x[5], x[6]}));
    chmax(h, evalHand({x[0], x[1], x[3], x[4], x[5]}));
    chmax(h, evalHand({x[0], x[1], x[3], x[4], x[6]}));
    chmax(h, evalHand({x[0], x[1], x[3], x[5], x[6]}));
    chmax(h, evalHand({x[0], x[1], x[4], x[5], x[6]}));
    chmax(h, evalHand({x[0], x[2], x[3], x[4], x[5]}));
    chmax(h, evalHand({x[0], x[2], x[3], x[4], x[6]}));
    chmax(h, evalHand({x[0], x[2], x[3], x[5], x[6]}));
    chmax(h, evalHand({x[0], x[2], x[4], x[5], x[6]}));
    chmax(h, evalHand({x[0], x[3], x[4], x[5], x[6]}));
    chmax(h, evalHand({x[1], x[2], x[3], x[4], x[5]}));
    chmax(h, evalHand({x[1], x[2], x[3], x[4], x[6]}));
    chmax(h, evalHand({x[1], x[2], x[3], x[5], x[6]}));
    chmax(h, evalHand({x[1], x[2], x[4], x[5], x[6]}));
    chmax(h, evalHand({x[1], x[3], x[4], x[5], x[6]}));
    chmax(h, evalHand({x[2], x[3], x[4], x[5], x[6]}));
    //for(auto a : x) cout << ("SHDC"[a.d]) << ("23456789TJQKA"[a.n-2]) << " ";
    //cout << "->";
    //for(auto a : h) cout << " " << a;
    //cout << "\n";
    return h;
}

void testcase(){
    string ch1 = "SHDC";
    string ch2 = "23456789TJQKA";
    vector<pair<string, Card>> allcards;
    rep(i,ch1.size()) rep(j,ch2.size()) allcards.push_back({ ch1.substr(i,1) + ch2.substr(j,1), { j+2,i } });
    sort(allcards.begin(), allcards.end(), [](pair<string, Card> l, pair<string, Card> r){ return l.first < r.first; });
    Card res[9];
    rep(i,7){
        string a; cin >> a;
        if(a == "#") exit(0);
        ll k = 0;
        rep(b,allcards.size()) if(allcards[b].first == a) k = b;
        res[i] = allcards[k].second;
        allcards.erase(allcards.begin() + k);
    }
    ll c0 = 0, c1 = 0, c2 = 0;
    rep(i,allcards.size()) rep(j,i){
        res[7] = allcards[i].second;
        res[8] = allcards[j].second;
        auto h1 = evalHand7({ res[0], res[1], res[4], res[5], res[6], res[7], res[8] });
        auto h2 = evalHand7({ res[2], res[3], res[4], res[5], res[6], res[7], res[8] });
        if(h2 < h1) c0++;
        else if(h1 < h2) c1++;
        else c2++;
    }
    double ans0 = double(c0) / double(c0+c1+c2);
    double ans1 = double(c1) / double(c0+c1+c2);
    double ans2 = double(c2) / double(c0+c1+c2);
    cout.precision(20);
    cout << fixed;
    cout << ans0 << "\n";
    //cout << ans1 << "\n";
    //cout << ans2 << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    while(true) testcase();
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3516
final_rank: 4

code_snippet: // AOJ #2535 Texas hold 'em
// 2025.3.18

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

struct Card {
    int suit;
    int rank;

    bool operator < (const Card &other) const {
        return rank < other.rank;
    }
};

struct HandStatus {
    int kind;
    int tieBreaker[6];

    bool operator > (const HandStatus &other) const {
        if (kind != other.kind)
            return kind < other.kind;
        for (int i = 1; i <= 5; i++) {
            if (tieBreaker[i] > other.tieBreaker[i])
                return true;
            if (tieBreaker[i] < other.tieBreaker[i])
                return false;
        }
        return false;
    }
};

Card cards[3][8], tempCards[3][8];
char inputStr[15];
int  win, total;
int  rankCount[15], suitCount[5];
bool usedCard[15][5];

Card readCard() {
    Card card;
    scanf("%s", inputStr + 1);
    if (inputStr[1] == '#') exit(0);

    if (inputStr[1] == 'S') card.suit = 1;
    else if (inputStr[1] == 'H') card.suit = 2;
    else if (inputStr[1] == 'D') card.suit = 3;
    else if (inputStr[1] == 'C') card.suit = 4;

    if (inputStr[2] >= '2' && inputStr[2] <= '9') card.rank = inputStr[2] - '0';
    else if (inputStr[2] == 'T') card.rank = 10;
    else if (inputStr[2] == 'J') card.rank = 11;
    else if (inputStr[2] == 'Q') card.rank = 12;
    else if (inputStr[2] == 'K') card.rank = 13;
    else if (inputStr[2] == 'A') card.rank = 14;
    return card;
}

HandStatus evaluateHand(int a) {
    HandStatus statusResult;
    for (int i = 1; i <= 5; i++) statusResult.tieBreaker[i] = 0;

    fill(rankCount + 1, rankCount + 15, 0);
    fill(suitCount + 1, suitCount + 5, 0);

    for (int i = 1; i <= 7; i++) {
        rankCount[tempCards[a][i].rank]++;
        suitCount[tempCards[a][i].suit]++;
    }

    for (int s = 1; s <= 4; s++) {
        if (suitCount[s] >= 5) {
            bool rankPresent[15] = { false };
            for (int i = 1; i <= 7; i++) {
                if (tempCards[a][i].suit == s) rankPresent[tempCards[a][i].rank] = true;
            }
            for (int r = 10; r >= 2; r--) {
                if (rankPresent[r] && rankPresent[r+1] && rankPresent[r+2] && rankPresent[r+3] && rankPresent[r+4]) {
                    if (r == 10) statusResult.kind = 1;
                    else {
                        statusResult.kind = 2;
                        statusResult.tieBreaker[1] = r + 4;
                    }
                    return statusResult;
                }
            }
            if (rankPresent[14] && rankPresent[2] && rankPresent[3] && rankPresent[4] && rankPresent[5]) {
                statusResult.kind = 2;
                statusResult.tieBreaker[1] = 5;
                return statusResult;
            }
        }
    }

    for (int r = 14; r >= 2; r--) {
        if (rankCount[r] == 4) {
            statusResult.kind = 3;
            statusResult.tieBreaker[1] = r;
            rankCount[r] -= 4;
            for (int k = 14; k >= 2; k--) {
                if (rankCount[k] > 0) {
                    statusResult.tieBreaker[2] = k;
                    break;
                }
            }
            return statusResult;
        }
    }

    int threeRank = 0, pairRank = 0;
    for (int r = 2; r <= 14; r++) {
        if (rankCount[r] >= 3) threeRank = r;
    }
    if (threeRank) {
        rankCount[threeRank] -= 3;
        for (int r = 2; r <= 14; r++) {
            if (rankCount[r] >= 2) pairRank = r;
        }
        if (pairRank) {
            statusResult.kind = 4;
            statusResult.tieBreaker[1] = threeRank;
            statusResult.tieBreaker[2] = pairRank;
            return statusResult;
        }
        rankCount[threeRank] += 3;
    }

    for (int s = 1; s <= 4; s++) {
        if (suitCount[s] >= 5) {
            statusResult.kind = 5;
            int count = 0;
            for (int i = 7; i >= 1; i--) {
                if (tempCards[a][i].suit == s && count < 5) {
                    statusResult.tieBreaker[++count] = tempCards[a][i].rank;
                }
            }
            return statusResult;
        }
    }

    for (int r = 10; r >= 2; r--) {
        if (rankCount[r] && rankCount[r+1] && rankCount[r+2] && rankCount[r+3] && rankCount[r+4]) {
            statusResult.kind = 6;
            statusResult.tieBreaker[1] = r + 4;
            return statusResult;
        }
    }
    if (rankCount[14] && rankCount[2] && rankCount[3] && rankCount[4] && rankCount[5]) {
        statusResult.kind = 6;
        statusResult.tieBreaker[1] = 5;
        return statusResult;
    }

    for (int r = 14; r >= 2; r--) {
        if (rankCount[r] == 3) {
            statusResult.kind = 7;
            statusResult.tieBreaker[1] = r;
            int count = 1;
            rankCount[r] -= 3;
            for (int k = 14; k >= 2; k--) {
                while (rankCount[k] > 0 && count < 3) {
                    statusResult.tieBreaker[++count] = k;
                    rankCount[k]--;
                }
                if (count >= 3) break;
            }
            return statusResult;
        }
    }

    {
        int firstPair = 0, secondPair = 0;
        for (int r = 2; r <= 14; r++) {
            if (rankCount[r] >= 2) firstPair = r;
        }
        if (firstPair) {
            rankCount[firstPair] -= 2;
            for (int r = 2; r <= 14; r++) {
                if (rankCount[r] >= 2) secondPair = r;
            }
            if (firstPair && secondPair) {
                rankCount[secondPair] -= 2;
                statusResult.kind = 8;
                statusResult.tieBreaker[1] = firstPair;
                statusResult.tieBreaker[2] = secondPair;
                for (int r = 14; r >= 2; r--) {
                    if (rankCount[r] > 0) {
                        statusResult.tieBreaker[3] = r;
                        break;
                    }
                }
                return statusResult;
            }
            rankCount[firstPair] += 2;
        }
    }

    for (int r = 14; r >= 2; r--) {
        if (rankCount[r] >= 2) {
            statusResult.kind = 9;
            statusResult.tieBreaker[1] = r;
            rankCount[r] -= 2;
            int count = 1;
            for (int k = 14; k >= 2; k--) {
                while (rankCount[k] > 0 && count < 4) {
                    statusResult.tieBreaker[++count] = k;
                    rankCount[k]--;
                }
                if (count >= 4) break;
            }
            return statusResult;
        }
    }

    statusResult.kind = 10;
    for (int i = 7; i >= 3; i--) statusResult.tieBreaker[7 - i + 1] = tempCards[a][i].rank;
    return statusResult;
}

bool isPlayer1Winner() {
    for (int i = 1; i <= 7; i++) {
        tempCards[1][i] = cards[1][i];
        tempCards[2][i] = cards[2][i];
    }
    sort(tempCards[1] + 1, tempCards[1] + 8);
    sort(tempCards[2] + 1, tempCards[2] + 8);

    HandStatus hand1 = evaluateHand(1);
    HandStatus hand2 = evaluateHand(2);

    return (hand1 > hand2);
}

int main() {
    while (true) {
        memset(usedCard, 0, sizeof(usedCard));
        win = total = 0;

        cards[1][1] = readCard();
        cards[1][2] = readCard();
        cards[2][1] = readCard();
        cards[2][2] = readCard();
        cards[1][3] = readCard();
        cards[1][4] = readCard();
        cards[1][5] = readCard();
        for (int i = 3; i <= 5; i++) cards[2][i] = cards[1][i];

        for (int player = 1; player <= 2; player++) {
            for (int i = 1; i <= 5; i++) {
                usedCard[cards[player][i].rank][cards[player][i].suit] = true;
            }
        }

        for (int suit1 = 1; suit1 <= 4; suit1++) {
            for (int rank1 = 2; rank1 <= 14; rank1++) {
                for (int suit2 = 1; suit2 <= 4; suit2++) {
                    for (int rank2 = 2; rank2 <= 14; rank2++) {
                        if (suit1 == suit2 && rank1 == rank2) continue;
                        if (usedCard[rank1][suit1] || usedCard[rank2][suit2])
                            continue;
                        cards[1][6] = Card{ suit1, rank1 };
                        cards[1][7] = Card{ suit2, rank2 };
                        cards[2][6] = cards[1][6];
                        cards[2][7] = cards[1][7];
                        total++;
                        if (isPlayer1Winner()) win++;
                    }
                }
            }
        }
        printf("%.20lf\n", double(win) / double(total));
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3532
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

pair<int,int> decode(string S) {
    pair<int,int> Ret;
    string A = "SHDC", B="A23456789TJQK";
    rep(i,0,4) {
        if (S[0] == A[i]) Ret.second = i;
    }
    rep(i,0,13) {
        if (S[1] == B[i]) Ret.first = i;
    }
    return Ret;
}

pair<int,vector<int>> Rank(vector<pair<int,int>> P) {
    bool Flush = true;
    rep(i,0,4) if (P[i].second != P[i+1].second) Flush = false;

    vector<int> COUNT(13,0);
    rep(i,0,5) COUNT[P[i].first]++;
    int Straight = -1;
    rep(i,4,14) {
        bool check = true;
        rep(j,0,5) {
            if (COUNT[(i-j)%13] != 1) check = false;
        }
        if (check) {
            Straight = i;
            break;
        }
    }

    vector<vector<int>> CS(5);
    rep(i,0,13) {
        CS[COUNT[i]].push_back((i==0 ? 13 : i));
    }
    rep(i,1,5) {
        sort(ALL(CS[i]));
        reverse(ALL(CS[i]));
    }

    if (Flush && Straight == 13) {
        return {9,{}};
    }
    
    if (Flush && Straight != -1) {
        return {8,{Straight}};
    }

    if (!CS[4].empty()) {
        return {7,{CS[4][0], CS[1][0]}};
    }

    if (!CS[3].empty() && !CS[2].empty()) {
        return {6,{CS[3][0], CS[2][0]}};
    }

    if (Flush) {
        vector<int> Ret;
        rep(i,0,5) {
            Ret.push_back((P[i].first == 0 ? 13 : P[i].first));
        }
        sort(ALL(Ret));
        reverse(ALL(Ret));
        return {5,Ret};
    }

    if (Straight != -1) {
        return {4,{Straight}};
    }

    if (!CS[3].empty()) {
        return {3,{CS[3][0],CS[1][0],CS[1][1]}};
    }

    if (CS[2].size() == 2) {
        return {2,{CS[2][0],CS[2][1],CS[1][0]}};
    }

    if (!CS[2].empty()) {
        return {1,{CS[2][0],CS[1][0],CS[1][1],CS[1][2]}};
    }

    return {0,{CS[1][0],CS[1][1],CS[1][2],CS[1][3],CS[1][4]}};
}

bool Win(vector<pair<int,int>> P, vector<pair<int,int>> Q) {
    auto PR = Rank(P), QR = Rank(Q);
    return PR > QR;
}

vector<pair<int,int>> Strong(vector<pair<int,int>> P) {
    vector<pair<int,int>> Ret = {P[2],P[3],P[4],P[5],P[6]};
    vector<int> ord = {0,0,1,1,1,1,1};
    do {
        vector<pair<int,int>> Q;
        rep(i,0,7) {
            if (ord[i]) Q.push_back(P[i]);
        }
        if (Win(Q,Ret)) Ret = Q;
    } while(next_permutation(ALL(ord)));
    return Ret;
}

bool Solve(vector<pair<int,int>> P, vector<pair<int,int>> Q) {
    auto X = Strong(P), Y = Strong(Q);
    return Win(X,Y);
}

int main() {
while(1) {
    string S;
    cin >> S;
    if (S == "#") return 0;
    vector<pair<int,int>> A(2), B(2), C(3);
    A[0] = decode(S);
    cin >> S;
    A[1] = decode(S);
    rep(i,0,2) {
        cin >> S;
        B[i] = decode(S);
    }
    rep(i,0,3) {
        cin >> S;
        C[i] = decode(S);
    }
    vector<vector<bool>> X(13,vector<bool>(4,true));
    rep(i,0,2) X[A[i].first][A[i].second] = false;
    rep(i,0,2) X[B[i].first][B[i].second] = false;
    rep(i,0,3) X[C[i].first][C[i].second] = false;
    int ANS = 0;
    rep(_,0,52) {
        int i = _/4, j = _%4;
        if (!X[i][j]) continue;
        rep(__,_+1,52) {
            int k = __/4, l = __%4;
            if (!X[k][l]) continue;
            vector<pair<int,int>> P, Q;
            P.push_back(A[0]), P.push_back(A[1]);
            Q.push_back(B[0]), Q.push_back(B[1]);
            P.push_back(C[0]), P.push_back(C[1]), P.push_back(C[2]);
            Q.push_back(C[0]), Q.push_back(C[1]), Q.push_back(C[2]);
            P.push_back({i,j}), P.push_back({k,l});
            Q.push_back({i,j}), Q.push_back({k,l});
            if (Solve(P,Q)) ANS++;
        }
    }
    printf("%.12f\n", (double)ANS / (45.0*22.0));
}
}
accuracy: 1
time_ms: 2970
memory_kb: 3572
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

pair<ll,ll> make_strongest(vector<pair<ll,ll>> C){
    sort(C.begin(),C.end());
    vector<int> CNT(14,0);
    vector<int> SUIT(4,0);
    for(int i=0;i<5;i++){
        CNT[C[i].first]++;
        SUIT[C[i].second]++;
    }

    vector<pair<int,int>> U(14);
    for(int i=0;i<14;i++){
        if(i!=1)U[i]={CNT[i],i};
        else U[i]={CNT[i],14};
    }
    sort(U.begin(),U.end());
    reverse(U.begin(),U.end());

    ll HC=C[4].first;
    if(C[0].first==1)HC=14;

    bool SAME_SUIT=0,STRAIGHT=1;
    for(int i=0;i<4;i++)if(C[i+1].first-C[i].first!=1)STRAIGHT=0;
    if(!STRAIGHT&&C[0].first==1){
        STRAIGHT=1;
        if(C[1].first!=10)STRAIGHT=0;
        for(int i=0;i<3;i++){
            if(C[i+2].first-C[i+1].first!=1)STRAIGHT=0;
        }
    }
    if(max({SUIT[0],SUIT[1],SUIT[2],SUIT[3]})==5)SAME_SUIT=1;
    pair<ll,ll> R={-1,-1};
    if(STRAIGHT){
        if(SAME_SUIT&&C[0].first==1&&C[1].first==10){
            R={9,14};
        }
        else if(SAME_SUIT){
            if(C[0].first==1&&C[1].first==10){
                R={8,14};
            }
            else{
                R={8,C[4].first};
            }
            ;
        }
        else {
            if(C[0].first==1&&C[1].first==10){
                R={4,14};
            }
            else{
                R={4,C[4].first};
            }
        }
    }
    if(SAME_SUIT){
        R=max(R,{5,U[0].second*200000+U[1].second*8000+U[2].second*400+U[3].second*20+U[4].second});
    }
    
    if(U[0].first==4){
        R=max(R,{7,U[0].second*20+U[1].second});
    }
    if(U[0].first==3){
        if(U[1].first==2){
            R=max(R,{6,U[0].second*20+U[1].second});
        }
        else{
            R=max(R,{3,U[0].second*400+U[1].second*20+U[2].second});
        }
    }
    if(U[0].first==2){
        if(U[1].first==2){
            R=max(R,{2,U[0].second*400+U[1].second*20+U[2].second});
        }
        else{
            R=max(R,{1,U[0].second*10000+U[1].second*400+U[2].second*20+U[3].second});
        }
    }

    R=max(R,{0,U[0].second*200000+U[1].second*8000+U[2].second*400+U[3].second*20+U[4].second});

    return R;
}

pair<ll,ll> ST_TO_CARD(string S){
    pair<ll,ll> R;
    if(S[0]=='S')R.second=0;
    else if(S[0]=='D')R.second=1;
    else if(S[0]=='H')R.second=2;
    else R.second=3;


    if(S[1]=='A')R.first=1;
    else if(S[1]=='T')R.first=10;
    else if(S[1]=='J')R.first=11;
    else if(S[1]=='Q')R.first=12;
    else if(S[1]=='K')R.first=13;
    else R.first=S[1]-'0';

    return R;
} 

void solve(bool &OKK){
    vector<pair<ll,ll>> MY,OP,BA;
    vector<vector<bool>> US(14,vector<bool>(4,0));
    for(int i=0;i<4;i++)US[0][i]=1;
    for(int i=0;i<2;i++){
        string S;
        cin>>S;
        if(S=="#"){
            OKK=0;
            return;
        }
        auto P=ST_TO_CARD(S);
        MY.push_back(P);
        US[P.first][P.second]=1;
    }
    for(int i=0;i<2;i++){
        string S;
        cin>>S;
        auto P=ST_TO_CARD(S);
        OP.push_back(P);
        US[P.first][P.second]=1;
    }
    for(int i=0;i<3;i++){
        string S;
        cin>>S;
        auto P=ST_TO_CARD(S);
        BA.push_back(P);
        US[P.first][P.second]=1;
    }
    ll an=0,bn=0;
    for(int i=0;i<52;i++){
        for(int j=0;j<i;j++){
            if(US[i%13+1][i/13])continue;
            if(US[j%13+1][j/13])continue;
            BA.push_back({i%13+1,i/13});
            BA.push_back({j%13+1,j/13});

            vector<int> P(7,0);
            for(int i=2;i<7;i++)P[i]=1;
            pair<ll,ll> MYH={-1,-1},OPH={-1,-1};
            do{
                vector<pair<ll,ll>> MYC,OPC;
                if(P[0]){
                    MYC.push_back(MY[0]);
                    OPC.push_back(OP[0]);
                }
                if(P[1]){
                    MYC.push_back(MY[1]);
                    OPC.push_back(OP[1]);
                }
                for(int p=2;p<7;p++){
                    if(P[p]){
                        MYC.push_back(BA[p-2]);
                        OPC.push_back(BA[p-2]);
                    }
                }
                MYH=max(MYH,make_strongest(MYC));
                OPH=max(OPH,make_strongest(OPC));

            }while(next_permutation(P.begin(),P.end()));
            // cout<<i%13+1<<" "<<i/13<<" "<<j%13+1<<" "<<j/13<<" "<<MYH.first<<" "<<MYH.second<<endl;
            an++;
            if(MYH>OPH)bn++;
            BA.resize(3);
        }
    }
    cout<<fixed<<setprecision(15)<<double(bn)/double(an)<<endl;
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    bool OKK=1;
    while(OKK)solve(OKK);
    
}
accuracy: 1
time_ms: 960
memory_kb: 3416
final_rank: 9

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define INF 1000000001
#define MOD 1000000007
#define MAX 1712304
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;

int win,lose,draw;

vector<int> arr;
vector<vector<int>> selectTable = {{0,1,2,3,4},{0,1,2,3,5},{0,1,2,3,6},{0,1,2,4,5},{0,1,2,4,6},{0,1,2,5,6},{0,1,3,4,5},{0,1,3,4,6},{0,1,3,5,6},{0,1,4,5,6},{0,2,3,4,5},{0,2,3,4,6},{0,2,3,5,6},{0,2,4,5,6},{0,3,4,5,6},{1,2,3,4,5},{1,2,3,4,6},{1,2,3,5,6},{1,2,4,5,6},{1,3,4,5,6},{2,3,4,5,6}};
pair<int,int> p1One,p1Two,p2One,p2Two;
vector<pair<int,int>> p1(5);
vector<pair<int,int>> p2(5);
vector<int> table(5);
int pw[5] = {1,14,196,2744,38416};
int precal [13][13][13][13][13];
int Score(vector<pair<int,int>> & p)
{
    bool flush = true;
    for(int i = 0; i<5; i++)
    {
        if(p[i].second != p[0].second)
            flush = false;
    }
    if(p[0].first == 0 && p[1].first == 9 && p[2].first == 10 && p[3].first == 11 && p[4].first == 12)
    {
        if(flush)
            return 1000000000;
        else
            return 599999999;
    }
    if(p[0].first+4 == p[1].first+3 && p[1].first+3 == p[2].first+2 && p[2].first+2 == p[3].first+1 && p[3].first+1 == p[4].first)
    {
        if(flush)
            return 900000000+p[4].first;
        else
            return 500000000+p[4].first;
    }

    if((p[0].first == p[3].first))
    {
        if(p[0].first == 0)
            return 800000000+13*pw[1]+p[4].first;
        return 800000000+p[2].first*pw[1]+p[4].first;
    }
    if((p[1].first == p[4].first))
    {
        if(p[0].first == 0)
            return 800000000+p[2].first*pw[1]+13;
        return 800000000+p[2].first*pw[1]+p[0].first;
    }

    if((p[0].first == p[1].first && p[2].first == p[4].first))
    {
        if(p[0].first == 0)
            return 700000000+p[2].first*pw[1]+13;
        return 700000000+p[2].first*pw[1]+p[0].first;
    }
    if((p[0].first ==  p[2].first && p[3].first == p[4].first))
    {
        if(p[0].first == 0)
            return 700000000+13*pw[1]+p[4].first;
        return 700000000+p[2].first*pw[1]+p[4].first;
    }

    if(flush)
    {
        if(p[0].first == 0)
            return 600000000+13*pw[4]+p[4].first*pw[3]+p[3].first*pw[2]+p[2].first*pw[1]+p[1].first;
        else
            return 600000000+p[4].first*pw[4]+p[3].first*pw[3]+p[2].first*pw[2]+p[1].first*pw[1]+p[0].first;
    }

    if((p[0].first ==  p[2].first))
    {
        if(p[0].first == 0)
            return 400000000+13*pw[2]+p[4].first*pw[1]+p[3].first;
        return 400000000+p[2].first*pw[2]+p[4].first*pw[1]+p[3].first;
    }
    if((p[1].first == p[3].first))
    {
        if(p[0].first == 0)
            return 400000000+p[2].first*pw[2]+13*pw[1]+p[4].first;
        return 400000000+p[2].first*pw[2]+p[4].first*pw[1]+p[0].first;
    }
    if((p[2].first == p[4].first))
    {
        if(p[0].first == 0)
            return 400000000+p[2].first*pw[2]+13*pw[1]+p[1].first;
        return 400000000+p[2].first*pw[2]+p[1].first*pw[1]+p[0].first;
    }

    if(p[0].first == p[1].first && p[2].first == p[3].first)
    {
        if(p[0].first == 0)
            return 300000000+13*pw[2]+p[2].first*pw[1]+p[4].first;
        else
            return 300000000+p[2].first*pw[2]+p[0].first*pw[1]+p[4].first;
    }
    if(p[0].first == p[1].first && p[3].first == p[4].first)
    {
        if(p[0].first == 0)
            return 300000000+13*pw[2]+p[3].first*pw[1]+p[2].first;
        else
            return 300000000+p[3].first*pw[2]+p[0].first*pw[1]+p[2].first;
    }
    if(p[1].first == p[2].first && p[3].first == p[4].first)
    {
        if(p[0].first == 0)
            return 300000000+p[4].first*pw[2]+p[2].first*pw[1]+13;
        else
            return 300000000+p[4].first*pw[2]+p[2].first*pw[1]+p[0].first;
    }

    if(p[0].first == p[1].first)
    {
        if(p[0].first == 0)
            return 200000000+13*pw[3]+p[4].first*pw[2]+p[3].first*pw[1]+p[2].first;
        else
            return 200000000+p[0].first*pw[3]+p[4].first*pw[2]+p[3].first*pw[1]+p[2].first;
    }
    if(p[1].first == p[2].first)
    {
        if(p[0].first == 0)
            return 200000000+p[1].first*pw[3]+13*pw[2]+p[4].first*pw[1]+p[3].first;
        else
            return 200000000+p[1].first*pw[3]+p[4].first*pw[2]+p[3].first*pw[1]+p[0].first;
    }
    if(p[2].first == p[3].first)
    {
        if(p[0].first == 0)
            return 200000000+p[2].first*pw[3]+13*pw[2]+p[4].first*pw[1]+p[1].first;
        else
            return 200000000+p[2].first*pw[3]+p[4].first*pw[2]+p[1].first*pw[1]+p[0].first;
    }
    if(p[3].first == p[4].first)
    {
        if(p[0].first == 0)
            return 200000000+p[3].first*pw[3]+13*pw[2]+p[2].first*pw[1]+p[1].first;
        else
            return 200000000+p[3].first*pw[3]+p[2].first*pw[2]+p[1].first*pw[1]+p[0].first;
    }
    if(p[0].first == 0)
        return 100000000+13*pw[4]+p[4].first*pw[3]+p[3].first*pw[2]+p[2].first*pw[1]+p[1].first;
    else
        return 100000000+p[4].first*pw[4]+p[3].first*pw[3]+p[2].first*pw[2]+p[1].first*pw[1]+p[0].first;
}
int FlushScore(vector<pair<int,int>> & p)
{
    if(p[0].first == 0 && p[1].first == 9 && p[2].first == 10 && p[3].first == 11 && p[4].first == 12)
        return 1000000000;
    if(p[0].first+4 == p[1].first+3 && p[1].first+3 == p[2].first+2 && p[2].first+2 == p[3].first+1 && p[3].first+1 == p[4].first)
        return 900000000+p[4].first;
    if(p[0].first == 0)
        return 600000000+13*pw[4]+p[4].first*pw[3]+p[3].first*pw[2]+p[2].first*pw[1]+p[1].first;
    else
        return 600000000+p[4].first*pw[4]+p[3].first*pw[3]+p[2].first*pw[2]+p[1].first*pw[1]+p[0].first;
}

void calResult()
{
    int val1 = 0, val2 = 0;
    for(int i = 0; i<21; i++)
    {
        for(int j = 0; j<5; j++)
        {
            int x = selectTable[i][j];
            if(x == 5)
            {
                p1[j] = p1One;
                p2[j] = p2One;
            }
            else if(x == 6)
            {
                p1[j] = p1Two;
                p2[j] = p2Two;
            }
            else
            {
                int shape = table[x]/13;
                int num = table[x]%13;
                p1[j].first = num;
                p1[j].second = shape;
                p2[j].first = num;
                p2[j].second = shape;
            }
        }
        bool flush = true;
        for(int j = 1; j<5; j++)
        {
            if(p1[0].second != p1[j].second)
            {
                flush = false;
                break;
            }
        }
        if(flush)
        {
            sort(all(p1));
            val1 = max(val1,FlushScore(p1));
        }
        else
            val1 = max(val1,precal[p1[0].first][p1[1].first][p1[2].first][p1[3].first][p1[4].first]);
        flush = true;
        for(int j = 1; j<5; j++)
        {
            if(p2[0].second != p2[j].second)
            {
                flush = false;
                break;
            }
        }
        if(flush)
        {
            sort(all(p2));
            val2 = max(val2,FlushScore(p2));
        }
        else
            val2 = max(val2,precal[p2[0].first][p2[1].first][p2[2].first][p2[3].first][p2[4].first]);
    }
    if(val1 == val2)
        draw++;
    else if(val1 > val2)
        win++;
    else
        lose++;
}

pair<int,int> trans(string &str)
{
    pair<int,int> result;

    if(str[1] >= '2' && str[1] <= '9')
        result.first = str[1]-'1';
    else if(str[1] == 'T')
        result.first = 9;
    else if(str[1] == 'A')
        result.first = 0;
    else if(str[1] == 'J')
        result.first = 10;
    else if(str[1] == 'Q')
        result.first = 11;
    else if(str[1] == 'K')
        result.first = 12;
    
    if(str[0] == 'S')
        result.second = 0;
    else if(str[0] == 'H')
        result.second = 1;
    else if(str[0] == 'D')
        result.second = 2;
    else if(str[0] == 'C')
        result.second = 3;
    return result;
}

void prepare()
{
    for(int i = 0; i < 13; i++)
    {
        for(int j = 0; j<13;j++)
        {
            for(int k = 0; k < 13; k++)
            {
                for(int l = 0; l<13; l++)
                {
                    for(int m = 0; m<13; m++)
                    {
                        p1[0] = {i,0};
                        p1[1] = {j,1};
                        p1[2] = {k,2};
                        p1[3] = {l,3};
                        p1[4] = {m,4};
                        sort(all(p1));
                        precal[i][j][k][l][m] = Score(p1);
                    }
                }
            }
        }
    }
}

int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);


    prepare();
    while(true)
    {
        string a;
        string b;
        cin >> a;
        if(a == "#")
            break;
        cin >> b;
        p1One = trans(a);
        p1Two = trans(b);
        cin >> a >> b;
        p2One = trans(a);
        p2Two = trans(b);

        win = 0;
        lose = 0;
        draw = 0;
        
        for(int i = 0; i<3; i++)
        {
            cin >> a;
            table[i] = trans(a).second*13 + trans(a).first;
        }
        arr.clear();
        for(int i = 0; i<52; i++)
        {
            if(i == p2Two.second*13+p2Two.first||i == p2One.second*13+p2One.first||i == p1Two.second*13+p1Two.first||i == p1One.second*13+p1One.first)
                continue;
            if(i == table[0] || i == table[1] || i == table[2])
                continue;
            arr.push_back(i);
        }

        for(int i = 0; i < 44; i++)
        {
            for(int j = i+1; j<45;j++)
            {
                table[3] = arr[i];
                table[4] = arr[j];
                calResult();
            }
        }
        cout << setprecision(10) << fixed;
        cout << ((double)win)/((double)(win+lose+draw)) << "\n";
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4968
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll get_card_id(string s)
{
	ll suitid=(s[0]=='S'?0:(s[0]=='H'?1:(s[0]=='D'?2:3)));
	ll valueid=(isdigit(s[1])?s[1]-'0':(s[1]=='A'?1:(s[1]=='T'?10:(s[1]=='J'?11:(s[1]=='Q'?12:13)))));
	return valueid*4+suitid;
}
vector<ll> get_rank(vector<ll> cards)
{
	ll i,j;
	bool same_suit=true,is_straight=true;
	sort(cards.begin(),cards.end());
	vector<ll> vals,suits;
	for(i=0;i<cards.size();i++)
	{
		vals.push_back(cards[i]/4);
		suits.push_back(cards[i]%4);
	}
	for(i=1;i<suits.size();i++)
	{
		same_suit&=(suits[i]==suits[i-1]);
		is_straight&=(vals[i]==vals[i-1]+1);
	}
	if(vals==(vector<ll>){1,10,11,12,13})
	{
		if(same_suit)
		{
			return {9,14,13,12,11,10};
		}
		return {4,14,13,12,11,10};
	}
	if(is_straight&&same_suit)
	{
		return {8,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	if(!is_straight)
	{
		for(i=0;i<vals.size();i++)
		{
			if(vals[i]==1)
			{
				vals[i]=14;
			}
		}
		sort(vals.begin(),vals.end());
	}
	if(vals[0]==vals[3])
	{
		return {7,vals[3],vals[2],vals[1],vals[0],vals[4]};
	}
	if(vals[1]==vals[4])
	{
		return {7,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	if(vals[0]==vals[2]&&vals[3]==vals[4])
	{
		return {6,vals[2],vals[1],vals[0],vals[4],vals[3]};
	}
	if(vals[0]==vals[1]&&vals[2]==vals[4])
	{
		return {6,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	if(same_suit)
	{
		return {5,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	if(is_straight)
	{
		return {4,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	if(vals[0]==vals[2])
	{
		return {3,vals[2],vals[1],vals[0],vals[4],vals[3]};
	}
	if(vals[1]==vals[3])
	{
		return {3,vals[3],vals[2],vals[1],vals[4],vals[0]};
	}
	if(vals[2]==vals[4])
	{
		return {3,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	if(vals[0]==vals[1]&&vals[2]==vals[3])
	{
		return {2,vals[3],vals[2],vals[1],vals[0],vals[4]};
	}
	if(vals[0]==vals[1]&&vals[3]==vals[4])
	{
		return {2,vals[4],vals[3],vals[1],vals[0],vals[2]};
	}
	if(vals[1]==vals[2]&&vals[3]==vals[4])
	{
		return {2,vals[4],vals[3],vals[2],vals[1],vals[0]};
	}
	for(i=0;i+1<vals.size();i++)
	{
		if(vals[i]==vals[i+1])
		{
			vector<ll> ret={1,vals[i],vals[i]};
			for(j=vals.size()-1;j>=0;j--)
			{
				if(vals[j]!=vals[i])
				{
					ret.push_back(vals[j]);
				}
			}
			return ret;
		}
	}
	return {0,vals[4],vals[3],vals[2],vals[1],vals[0]};
}
ll s1,s2,t1,t2,a1,a2,a3;
bool vis[60];
vector<ll> calc(vector<ll> allc)
{
	ll i,j,k;
	vector<ll> ret={-INF,-INF,-INF,-INF,-INF,-INF};
	for(i=0;i<allc.size();i++)
	{
		for(j=i+1;j<allc.size();j++)
		{
			vector<ll> v;
			for(k=0;k<allc.size();k++)
			{
				if(k!=i&&k!=j)
				{
					v.push_back(allc[k]);
				}
			}
			vector<ll> nw=get_rank(v);
			ret=max(ret,nw);
		}
	}
	return ret;
}
int main(){
	ll i,j;
	string s;
	while(true)
	{
		cin>>s;
		if(s=="#")
		{
			break;
		}
		s1=get_card_id(s);
		cin>>s;s2=get_card_id(s);
		cin>>s;t1=get_card_id(s);
		cin>>s;t2=get_card_id(s);
		cin>>s;a1=get_card_id(s);
		cin>>s;a2=get_card_id(s);
		cin>>s;a3=get_card_id(s);
		memset(vis,false,sizeof(vis));
		vis[s1]=vis[s2]=vis[t1]=vis[t2]=vis[a1]=vis[a2]=vis[a3]=true;
		ll ans=0,tot=0;
		for(i=4;i<56;i++)
		{
			if(vis[i])
			{
				continue;
			}
			for(j=i+1;j<56;j++)
			{
				if(vis[j])
				{
					continue;
				}
				tot++;
				vector<ll> v1=calc({s1,s2,a1,a2,a3,i,j}),v2=calc({t1,t2,a1,a2,a3,i,j});
				ans+=(v1>v2);
			}
		}
		printf("%.16lf\n",(double)ans/(double)tot);
	}
	return 0;
}
accuracy: 1
time_ms: 1210
memory_kb: 3500
final_rank: 11

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

string suit = "SHDC";
string number = "23456789TJQKA";

enum hand {
	high_card,
	one_pair,
	two_pair,
	three_of_a_kind,
	straight,
	hand_flush,
	full_house,
	four_of_a_kind,
	straight_flush,
	royal_straight_flush,
};

vector<vector<int>> tie_same_number(vector<int> cards) {
	sort(cards.begin(), cards.end());
	reverse(cards.begin(), cards.end());
	vector<vector<vector<int>>> cards_num(5, vector<vector<int>>(0, vector<int>(0)));
	
	int cur = 0;
	for (int i = 13 - 1; i >= 0; i--)
	{
		vector<int> cards_cur(0);
		while (cur < cards.size() && cards[cur] / 4 == i) {
			cards_cur.push_back(cards[cur]);
			cur++;
		}
		if (cards_cur.size() > 0) {
			cards_num[cards_cur.size()].push_back(cards_cur);
		}
	}
	vector<vector<int>> ret(0, vector<int>(0));
	for (int i = 5 - 1; i >= 0; i--)
	{
		for (int j = 0; j < cards_num[i].size(); j++)
		{
			if (cards_num[i][j].size() > 0) {
				ret.push_back(cards_num[i][j]);
			}
		}
	}
	return ret;
}

vector<int> max_straight(vector<int> cards) {
	sort(cards.begin(), cards.end());
	reverse(cards.begin(), cards.end());
	int max_size = 0;
	vector<vector<int>> ret(0, vector<int>(0));
	vector<int> cur(0);
	for (size_t i = 0; i < cards.size(); i++)
	{
		if (cur.size() == 0) {
			cur.push_back(cards[i]);
		}
		else if (cur[cur.size() - 1] / 4 - 1 == cards[i] / 4) {
			cur.push_back(cards[i]);
		}
		else if (cur[cur.size() - 1] / 4 == cards[i] / 4) {
			continue;
		}
		else {
			if (cur.size() > 0 && cur[cur.size() - 1] / 4 == 0 && cards[0] / 4 == 12) {
				cur.push_back(cards[0]);
			}
			ret.push_back(cur);
			max_size = max(max_size, (int)cur.size());
			cur = vector<int>(0);
			cur.push_back(cards[i]);
		}
	}
	if (cur.size() > 0 && cur[cur.size() - 1] / 4 == 0 && cards[0] / 4 == 12) {
		cur.push_back(cards[0]);
	}
	max_size = max(max_size, (int)cur.size());
	ret.push_back(cur);
	for (size_t i = 0; i < ret.size(); i++)
	{
		if (ret[i].size() == max_size) {
			return ret[i];
		}
	}
	return vector<int>{};
}

vector<int> max_suit(vector<int> cards) {
	vector<vector<int>> cards_suit(4, vector<int>(0));
	for (size_t i = 0; i < cards.size(); i++)
	{
		cards_suit[cards[i] % 4].push_back(cards[i]);
	}
	for (size_t i = 0; i < 4; i++)
	{
		sort(cards_suit[i].begin(), cards_suit[i].end());
		reverse(cards_suit[i].begin(), cards_suit[i].end());
		if (cards_suit[i].size() >= 5) {
			return cards_suit[i];
		}
	}
	return cards_suit[0];
}

vector<int> compress(vector<vector<int>> cards, int layer) {
	vector<int> rest(0);
	for (size_t i = layer; i < cards.size(); i++)
	{
		for (size_t j = 0; j < cards[i].size(); j++)
		{
			rest.push_back(cards[i][j]);
		}
	}
	sort(rest.begin(), rest.end());
	reverse(rest.begin(), rest.end());
	vector<int> ret(0);
	for (size_t i = 0; i < layer; i++)
	{
		for (size_t j = 0; j < cards[i].size(); j++)
		{
			ret.push_back(cards[i][j]);
		}
	}
	for (size_t i = 0; i < rest.size(); i++)
	{
		ret.push_back(rest[i]);
	}
	return ret;
}

int to_strength(vector<int> cards) {
	int ret = 0;
	for (size_t i = 0; i < 5; i++)
	{
		ret *= 13;
		ret += cards[i] / 4;
	}
	return ret;
}

pair<hand, int> calc_hand(vector<int> cards) {
	auto cards_num_group = tie_same_number(cards);
	auto cards_straight = max_straight(cards);
	auto cards_suit = max_suit(cards);
	auto cards_straight_flush = max_straight(cards_suit);
	if (cards_straight_flush.size() >= 5) {
		int strength = to_strength(cards_straight_flush);
		if (cards_straight_flush[0] / 4 == 12) {
			return pair<hand, int>(royal_straight_flush, strength);
		}
		else {
			return pair<hand, int>(straight_flush, strength);
		}
	}
	if (cards_num_group[0].size() == 4) {
		vector<int> compressed = compress(cards_num_group, 1);
		int strength = to_strength(compressed);
		return pair<hand, int>(four_of_a_kind, strength);
	}
	if (cards_num_group[0].size() == 3 && cards_num_group[1].size() >= 2) {
		vector<int> compressed = compress(cards_num_group, 2);
		int strength = to_strength(compressed);
		return pair<hand, int>(full_house, strength);
	}
	if (cards_suit.size() >= 5) {
		int strength = to_strength(cards_suit);
		return pair<hand, int>(hand_flush, strength);
	}
	if (cards_straight.size() >= 5) {
		int strength = to_strength(cards_straight);
		return pair<hand, int>(straight, strength);
	}
	if (cards_num_group[0].size() == 3) {
		vector<int> compressed = compress(cards_num_group, 1);
		int strength = to_strength(compressed);
		return pair<hand, int>(three_of_a_kind, strength);
	}
	if (cards_num_group[0].size() == 2 && cards_num_group[1].size() == 2) {
		vector<int> compressed = compress(cards_num_group, 2);
		int strength = to_strength(compressed);
		return pair<hand, int>(two_pair, strength);
	}
	if (cards_num_group[0].size() == 2) {
		vector<int> compressed = compress(cards_num_group, 1);
		int strength = to_strength(compressed);
		return pair<hand, int>(one_pair, strength);
	}
	vector<int> compressed = compress(cards_num_group, 0);
	int strength = to_strength(compressed);
	return pair<hand, int>(high_card, strength);
}

int to_card_id(string hand) {
	int ret = 0;
	for (size_t i = 0; i < 4; i++)
	{
		if (hand[0] == suit[i]) ret += i;
	}
	for (size_t i = 0; i < 13; i++)
	{
		if (hand[1] == number[i]) ret += 4 * i;
	}
	return ret;
}

string to_card_str(int id) {
	string ret = "";
	ret += suit[id % 4];
	ret += number[id / 4];
	return ret;
}

bool is_win(vector<int> your_cards, vector<int> opponent_cards) {
	auto your_hand_pair = calc_hand(your_cards);
	auto opponent_hand_pair = calc_hand(opponent_cards);
	
	hand your_hand = your_hand_pair.first;
	int your_hand_strength = your_hand_pair.second;
	hand opponent_hand = opponent_hand_pair.first;
	int opponent_hand_strength = opponent_hand_pair.second;

	if (your_hand != opponent_hand) {
		return your_hand > opponent_hand;
	}
	if (your_hand == royal_straight_flush) {
		return false;
	}
	return your_hand_strength > opponent_hand_strength;
}

int main(){
	
	while (true){
		vector<int> your_cards(0);
		vector<int> opponent_cards(0);
		vector<int> all_cards(0);

		for (size_t i = 0; i < 2; i++)
		{
			string _s;
			cin >> _s;
			if (_s == "#") break;
			int id = to_card_id(_s);
			your_cards.push_back(id);
			all_cards.push_back(id);
		}
		if (your_cards.size() == 0) break;
		for (size_t i = 0; i < 2; i++)
		{
			string _s;
			cin >> _s;
			int id = to_card_id(_s);
			opponent_cards.push_back(id);
			all_cards.push_back(id);
		}
		for (size_t i = 0; i < 3; i++)
		{
			string _s;
			cin >> _s;
			int id = to_card_id(_s);
			your_cards.push_back(id);
			opponent_cards.push_back(id);
			all_cards.push_back(id);
		}
		
		ll cnt_all = 0;
		ll cnt_win = 0;

		for (size_t i = 0; i < 52; i++)
		{
			if (find(all_cards.begin(), all_cards.end(), i) != all_cards.end()) continue;
			your_cards.push_back(i);
			opponent_cards.push_back(i);

			for (size_t j = i + 1; j < 52; j++)
			{
				if (find(all_cards.begin(), all_cards.end(), j) != all_cards.end()) continue;
				your_cards.push_back(j);
				opponent_cards.push_back(j);
				
				cnt_all++;
				if (is_win(your_cards, opponent_cards)) {
					cnt_win++;
				}

				your_cards.pop_back();
				opponent_cards.pop_back();
			}

			your_cards.pop_back();
			opponent_cards.pop_back();
		}
		

		cout << setprecision(11) << (cnt_win + 0.0) / cnt_all << endl;		
	}
}
accuracy: 1
time_ms: 270
memory_kb: 3596
final_rank: 6

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

namespace POKER
{
	int Suits[260],Ranks[260];
	inline void init()
	{
		memset(Suits,-1,sizeof Suits) , memset(Ranks,-1,sizeof Ranks);
		Suits['C']=0 , Suits['D']=1 , Suits['H']=2 , Suits['S']=3;
		for(int i=2;i<=9;++i)Ranks[i+'0']=i-2;
		Ranks['T']=8 , Ranks['J']=9 , Ranks['Q']=10 , Ranks['K']=11 , Ranks['A']=12;
	}
	inline int str2int(const string &s)//s长度为2 
	{
	    return Suits[s[0]]*13+Ranks[s[1]];
	}
	/*const string suits = "CDHS";//4
	const string ranks = "23456789TJQKA";//13
	int str2int(const string &s)
	{
	    int res=0;
	    for(int i=0;i<4;++i)
	        if(s[0]==suits[i])res += i*13;
	    for(int i=0;i<13;++i)
	        if(s[1]==ranks[i])res += i;
	    return res;
	}*/
	
	
	vector<int> highest_hand(const vector<int> &a)
	{
		assert(a.size()==7);//7选5 
		
	    vector<bitset<13> >c(4, 0);
	    vector<int> suits(4, 0);//返回牌数 
	    vector<int> ranks(13, 0);//返回牌数 
	    for(int i=0; i<(int)a.size(); ++i)
		{
	        int suit = a[i]/13;
	        int rank = a[i]%13;
	        c[suit][rank] = true;
	        suits[suit]++;
	        ranks[rank]++;
	    }
	    vector<vector<int> >n2r(5/*牌数n*/);//返回 n张牌的rank集合（即ranks的逆映射） 
	    for(int i=12; i>=0; --i)
		{
	        n2r[ranks[i]].push_back(i);
	    }
	
	    // (royal) straight flush
	    for(int i=0; i<4; ++i)
	        for(int j=12; j>=3; --j)//j=12是royal同花顺最大 
			{
	            bool ok = true;
	            for(int k=0; k<5; ++k)
				{
	                int rank = (j-k>=0)? j-k: 12;
	                if(!c[i][rank])
					{
	                    ok = false;
	                    break;
	                }
	            }
	            if(ok) return {8, j};
	        }
	    
	    // four of a kind
	    if(!n2r[4].empty())
		{
	        for(int i=12; i>=0; --i)
			{
	            if(ranks[i]==0 or i==n2r[4][0]) continue;//不可能5张牌同一个rank 
	            return {7, n2r[4][0], i};
	        }
	    }
	    // full house
	    if(!n2r[3].empty() and (n2r[3].size() +n2r[2].size())>=2u)
		{
	        for(int i=12; i>=0; --i)
			{
	            if(i==n2r[3][0] or ranks[i]<2) continue;
	            return {6, n2r[3][0], i};
	        }
	    }
	    // flush 
	    for(int i=0; i<4; ++i)
		{
	        if(suits[i] < 5) continue;
	        vector<int> res{5};
	        for(int j=12; j>=0; --j)
			{
	            if(c[i][j]) res.push_back(j);
	            if((int)res.size() == 6) return res;
	        }
	    }
	    // straight
	    for(int i=12; i>=3; --i)//i=12是最大的顺子（TJQKA） 
		{
	        bool ok = true;
	        for(int j=0; j<5; ++j)
			{
	            int rank = (i-j>=0)? i-j: 12;
	            if(ranks[rank] == 0)
				{
	                ok = false;
	                break;
	            }
	        }
	        if(ok) return {4, i};
	    }
	    // three of a kind:
	    if(!n2r[3].empty())
		{
	        return {3, n2r[3][0], n2r[1][0], n2r[1][1]};
	    }
	    // two pairs
	    if((int)n2r[2].size() >= 2)
		{
	        int rem = (n2r[2].size()>2u)? max(n2r[2][2], n2r[1][0]): n2r[1][0];
	        return {2, n2r[2][0], n2r[2][1], rem};
	    }
	    // pair
	    if((int)n2r[2].size() == 1)
		{
	        return {1, n2r[2][0], n2r[1][0], n2r[1][1], n2r[1][2]};
	    }
	    
	    //highcard
	    vector<int> res{0};
	    res.insert(res.end(), n2r[1].begin(), n2r[1].begin()+5);
	    return res;
	}
	
	
	void work(string tmp)
	{
		vector<int> c(7);//01为A起手牌，23为B起手牌，456为公共牌 
        c[0] = str2int(tmp);
        for(int i=1; i<7; ++i)
		{
            string ss;
            cin >> ss;
            c[i] = str2int(ss);
        }
        
        bitset<52> used = 0;
        for(int i=0; i<7; ++i)
            used[c[i]] = true;
        
        int total = 0;
        int wins = 0;
        for(int i=0; i<52; ++i)
            for(int j=i+1; j<52; ++j)
            {
                if(used[i] or used[j]) continue;
                vector<int> a{c[0], c[1], c[4], c[5], c[6], i, j};
                vector<int> b{c[2], c[3], c[4], c[5], c[6], i, j};
                if(highest_hand(a) > highest_hand(b)) wins++;
                total++;
            }
        
        cout << fixed << setprecision(10);
        cout << (double)wins/total << endl;
	}
}

int main()
{
	ios::sync_with_stdio(0);
	POKER::init();
    while(1)
	{
        string tmp;
        cin>>tmp;
        if(tmp=="#")break;
        POKER::work(tmp);
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3488
final_rank: 3

code_snippet: #pragma region template
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
 #include <debug>
#else
 #define debug(...) void(0)
#endif

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using pi=pair<int,int>;
using pll=pair<ll,ll>;

#define overload2(a,b,c,...) c
#define overload3(a,b,c,d,...) d
#define overload4(a,b,c,d,e,...) e
#define overload5(a,b,c,d,e,f,...) f

#define TYPE1(T) template<typename T>
#define TYPE2(T,U) template<typename T,typename U>
#define TYPE(...) overload2(__VA_ARGS__,TYPE2,TYPE1)(__VA_ARGS__)
#define TYPES1(T) template<typename... T>
#define TYPES2(H,T) template<typename H,typename... T>
#define TYPES(...) overload2(__VA_ARGS__,TYPES2,TYPES1)(__VA_ARGS__)

#define REP4(i,s,n,d) for(ll i=(s);i<(n);i+=(d))
#define REP3(i,s,n) REP4(i,s,n,1)
#define REP2(i,n) REP3(i,0,n)
#define REP1(n) REP2(tomato,n)
#define REP(...) overload4(__VA_ARGS__,REP4,REP3,REP2,REP1)(__VA_ARGS__)

#define RREP4(i,s,n,d) for(ll i=(n)-1;i>=s;i-=d)
#define RREP3(i,s,n) RREP4(i,s,n,1)
#define RREP2(i,n) RREP3(i,0,n)
#define RREP1(n) RREP2(tomato,n)
#define RREP(...) overload4(__VA_ARGS__,RREP4,RREP3,RREP2,RREP1)(__VA_ARGS__)

#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(RALL(v))
#define REVERSE(v) reverse(ALL(v))
#define UNIQUE(v) SORT(v),v.erase(unique(ALL(v)),v.end())

TYPES(T) void input(T&... a){ (cin>>...>>a); }
#define DECLARE(T,...) T __VA_ARGS__;input(__VA_ARGS__);
#define INT(...) DECLARE(int,__VA_ARGS__)
#define STR(...) DECLARE(string,__VA_ARGS__)
#define LL(...) DECLARE(long long,__VA_ARGS__)
#define CHR(...) DECLARE(char,__VA_ARGS__)
#define DBL(...) DECLARE(double,__VA_ARGS__)

TYPE(T)
istream&operator>>(istream&is,vector<T>&v){
  for(auto&a:v)cin>>a;
  return is;
}
TYPE(T)
ostream&operator<<(ostream&os,vector<T>&v){
  if(&os==&cerr)os<<"[";
  REP(i,v.size()){
    os<<v[i];
    if(i+1<v.size())os<<(&os==&cerr?",":" ");
  }
  if(&os==&cerr)os<<"]";
  return os;
}

#pragma endregion template

int hoge(char c){
  if(c>='2' and c<='9')return c-'2';
  if(c=='T')return 8;
  if(c=='J')return 9;
  if(c=='Q')return 10;
  if(c=='K')return 11;
  assert(c=='A');
  return 12;
}
int huga(char c){
  if(c=='S')return 3;
  if(c=='H')return 2;
  if(c=='D')return 1;
  assert(c=='C');
  return 0;
}

pi card(string s){
  return pi(hoge(s[1]),huga(s[0]));
}

template<typename T>
bool chmax(T &a,T b){
  return (a<b&&(a=b,true));
}

pi fres(const vector<pi>&s){
  bool flush=true;
  REP(i,4)if(s[i].second!=s[i+1].second)flush=false;
  bool straight=true;
  REP(i,4)if(s[i].first+1!=s[i+1].first)straight=false;

  bool astraight=s.back().first==12;
  REP(i,4)if(s[i].first!=i)astraight=false;
  straight|=astraight;
  
  if(straight and flush and s[0].first==8)return pi(10,0);
  if(straight and flush)return pi(9,(astraight?3:s.back().first));

  map<int,int> mp;
  for(auto[fi,se]:s)mp[fi]++;
  vector<pi> w;
  for(auto [key,val]:mp)w.emplace_back(val,key);
  sort(ALL(w));

  int a=0;
  RREP(i,w.size())a=a*13+w[i].second;

  if(w.size()==2){
    if(w[1].first==4)return pi(8,a);
    return pi(7,a);
  }
  if(flush)return pi(6,a);
  if(straight)return pi(5,(astraight?3:s.back().first));
  if(w.size()==3){
    if(w.back().first==3)return pi(4,a);
    return pi(3,a);
  }
  if(w.size()==4)return pi(2,a);
  return pi(1,a);
}

pi result(vector<pi> s){
  SORT(s);
  pi res(0,0);
  vector<int> v(7,1);
  v[0]=v[1]=0;
  vector<pi> rem(5);
  do{
    int cnt=0;
    REP(i,7)if(v[i])rem[cnt++]=s[i];
    chmax(res,fres(rem));
  }while(next_permutation(ALL(v)));
  return res;
}  

ld solve(){
  vector<pi> a(7);
  REP(i,7){
    STR(s);
    if(s=="#")exit(0);
    a[i]=card(s);
  }
  vector<pi> rem;rem.reserve(52-7);
  REP(i,13)REP(j,4){
    pi t(i,j);
    bool ok=true;
    for(pi p:a)if(p==t)ok=false;
    if(ok)rem.push_back(t);
  }
  //assert(rem.size()==52-7);
  ld win=0;
  int cnt=0;
  REP(i,rem.size())REP(j,i){
    cnt++;
    auto my=a;
    auto op=a;
    my[2]=rem[i],my[3]=rem[j];
    op[0]=rem[i],op[1]=rem[j];
    if(result(my)>result(op))win++;
  }
  return win/ld(cnt);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  /*vector<pi> v(5);
  v[0]={0,0};
  v[1]={1,0};
  v[2]={2,0};
  v[3]={3,0};
  v[4]={12,0};
  debug(fres(v));
  return 0;*/

  cout<<fixed<<setprecision(12);

  while(true)cout<<solve()<<"\n";
}
accuracy: 1
time_ms: 730
memory_kb: 3504
final_rank: 8

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
//const int mod = 1e9 + 7;
const int mod = 998244353;

map<char,int> mp;

vector<int> yaku(vector<string> s){
	assert(s.size() == 7);
	vl nxt(7,1);
	rep(i,2) nxt[i] = 0;
	vector<int> res = {0,0,0,0,0,0};
	do{
		vector<string> sel;
		rep(i,7) if(nxt[i] == 1) sel.emplace_back(s[i]);
		char c = sel[0][0];
		bool strai = true;
		vector<int> num;
		rep(i,5){
			if(sel[i][0] != c) c = '@';
			num.push_back(mp[sel[i][1]]);
		}
		sort(all(num));
		rep(i,4){
			if(num[i]+1 != num[i+1]){
				if(i > 0 || num[i] != 1 || num[i+1] != 10) strai = false;
			}
		}
		if(c != '@' && strai){
			if(num[0] == 1 && num[1] == 10) res = {9,0,0,0,0,0}; //ロイヤル
			else chmax(res, vector<int>{8,num[4],0,0,0,0}); //ストフラ
		}else{
			if(strai){ //ストレート
				if(num[0] == 1){
					if(num[4] == 13) chmax(res, vector<int>{4,14,0,0,0,0});
					else chmax(res, vector<int>{4,5,0,0,0,0});
				}else{
					chmax(res, vector<int>{4,num[4],0,0,0,0});
				}
			}
			//1->14に移行
			while(num[0] == 1){
				num.erase(num.begin());
				num.push_back(14);
			}
			if(c != '@'){ //フラッシュ
				chmax(res, vector<int>{5,num[4],num[3],num[2],num[1],num[0]});
			}
			map<int,int> cnt;
			rep(i,5) cnt[num[i]]++;
			//debug(sel,num);
			if(cnt.size() == 2){
				int S = 0;
				for(auto x : cnt) S += x.first;
				for(auto x : cnt){
					if(x.second == 4){
						chmax(res, vector<int>{7,x.first,S-x.first,0,0,0}); //4カード
					}
					if(x.second == 3){
						chmax(res, vector<int>{6,x.first,S-x.first,0,0,0}); //フルハウス
					}
				}
			}else{
				vector<pii> p;
				for(auto x : cnt) p.emplace_back(x.second,x.first);
				int sz = p.size();
				sort(rall(p));
				if(p[0].first == 3){
					int mx = max(p[1].second,p[2].second);
					int mn = min(p[1].second,p[2].second);
					chmax(res, vector<int>{3,p[0].second,mx,mn,0,0}); //3カード
				}
				else if(p[0].first == 2){
					if(p[1].first == 2){
						int mx = max(p[0].second,p[1].second);
						int mn = min(p[0].second,p[1].second);
						chmax(res, vector<int>{2,mx,mn,p[2].second,0,0}); //2ペア
					}else{
						int mx = max({p[1].second,p[2].second,p[3].second});
						int mn = min({p[1].second,p[2].second,p[3].second});
						int mid = p[1].second+p[2].second+p[3].second-mx-mn;
						chmax(res, vector<int>{1,p[0].second,mx,mid,mn,0});
					}
				}
				else{
					chmax(res, vector<int>{0,num[4],num[3],num[2],num[1],num[0]});
				}
			}
		}
	}while(next_permutation(all(nxt)));
	return res;
}

int main(){
	while(1){
		vector<string> s(2),t(2);
		cin >> s[0];
		if(s[0] == "#") break;
		cin >> s[1];
		rep(i,2) cin >> t[i];
		rep(i,3){
			string u; cin >> u;
			s.emplace_back(u);
			t.emplace_back(u);
		}
		mp['A'] = 1, mp['T'] = 10, mp['J'] = 11, mp['Q'] = 12, mp['K'] = 13;
		REP(i,2,10) mp[(char)('0'+i)] = i; 
		string suits = "SHDC";
		string nums = "A23456789TJQK";
		double ans = 0;
		set<pii> se;
		rep(i,5){
			rep(j,4){
				if(s[i][0] == suits[j]) se.emplace(j,mp[s[i][1]]);
				if(t[i][0] == suits[j]) se.emplace(j,mp[t[i][1]]);
			}
		}
		int cnt = 0;
		rep(i,4) REP(j,1,14) rep(k,4) REP(l,1,14){
			if(pii(i,j) == pii(k,l)) continue;
			if(se.count(pii(i,j)) || se.count(pii(k,l))) continue;
			string p = ""; p += suits[i]; p += nums[j-1];
			string q = ""; q += suits[k]; q += nums[l-1];
			s.emplace_back(p);
			t.emplace_back(p);
			s.emplace_back(q);
			t.emplace_back(q);
			cnt++;
			if(yaku(s) > yaku(t)){
				ans++;
			}
			rep(m,2) s.pop_back(), t.pop_back();
		}
		ans /= cnt;
		printf("%.10f\n",ans);
	}
}
accuracy: 1
time_ms: 3590
memory_kb: 3512
final_rank: 18

code_snippet: #include <bits/stdc++.h>

struct card {
	//S->0, H->1, D->2, C->3
	int suit;
	int rank;
	card() = default;
	card(std::string s) {
		assert(s.size() == 2);
		suit = s[0] == 'S' ? 0 : s[0] == 'H' ? 1 : s[0] == 'D' ? 2 : 3;
		rank = s[1] <= '9' ? s[1] - '0' : s[1] == 'T' ? 10 : s[1] == 'J' ? 11 : s[1] == 'Q' ? 12 : s[1] == 'K' ? 13 : 14;
	}
	card(int id) {
		suit = id / 13;
		rank = id % 13 + 2;
	}
	int id() { return suit * 13 + rank - 2; }
	bool operator<(card oth) {
		return rank < oth.rank;
	}
};

std::vector<int> eval(std::vector<card> a) {
	assert(a.size() == 5);
	sort(a.begin(), a.end());
	std::set<int> suits;
	for(const auto &c : a) suits.insert(c.suit);
	if(suits.size() == 1 and a.back().rank - a.front().rank == 4) {
		if(a.back().rank == 14)
			return {9};
		else
			return {8, a.back().rank};
	}
	if(suits.size() == 1 and a.back().rank == 14 and a[3].rank == 5) {
		return {8, 5};
	}
	if(a[0].rank == a[3].rank or a[1].rank == a[4].rank) {
		bool tmp = a[0].rank == a[3].rank;
		return {7, tmp ? a[0].rank : a[4].rank, tmp ? a[4].rank : a[0].rank};
	}
	if((a[0].rank == a[2].rank and a[3].rank == a[4].rank) or (a[2].rank == a[4].rank and a[0].rank == a[1].rank)) {
		bool tmp = a[0].rank == a[2].rank;
		return {6, tmp ? a[0].rank : a[4].rank, tmp ? a[4].rank : a[0].rank};
	}
	if(suits.size() == 1) {
		return {5, a[4].rank, a[3].rank, a[2].rank, a[1].rank, a[0].rank};
	}
	bool straight = true;
	for(int i = 0; i < 4; i++) straight &= a[i + 1].rank - a[i].rank == 1;
	if(straight) { return {4, a[4].rank}; }
	if(a[0].rank == 2 and a[1].rank == 3 and a[2].rank == 4 and a[3].rank == 5 and a[4].rank == 14) {
		return {4, 5};
	}
	if(a[0].rank == a[2].rank) {
		return {3, a[0].rank, a[4].rank, a[3].rank};
	}
	if(a[1].rank == a[3].rank) {
		return {3, a[1].rank, a[4].rank, a[0].rank};
	}
	if(a[2].rank == a[4].rank) {
		return {3, a[2].rank, a[1].rank, a[0].rank};
	}
	if(a[0].rank == a[1].rank) {
		if(a[2].rank == a[3].rank)
			return {2, a[2].rank, a[0].rank, a[4].rank};
		if(a[3].rank == a[4].rank)
			return {2, a[3].rank, a[0].rank, a[2].rank};
	}
	if(a[1].rank == a[2].rank) {
		if(a[3].rank == a[4].rank)
			return {2, a[3].rank, a[1].rank, a[0].rank};
	}
	if(a[0].rank == a[1].rank) {
		return {1, a[0].rank, a[4].rank, a[3].rank, a[2].rank};
	}
	if(a[1].rank == a[2].rank) {
		return {1, a[1].rank, a[4].rank, a[3].rank, a[0].rank};
	}
	if(a[2].rank == a[3].rank) {
		return {1, a[2].rank, a[4].rank, a[1].rank, a[0].rank};
	}
	if(a[3].rank == a[4].rank) {
		return {1, a[3].rank, a[2].rank, a[1].rank, a[0].rank};
	}
	return {0, a[4].rank, a[3].rank, a[2].rank, a[1].rank, a[0].rank};
}

std::vector<int> eval2(std::vector<card> a) {
	assert(a.size() == 7);
	std::vector<int> p{0, 0, 1, 1, 1, 1, 1};
	std::vector<int> ret;
	do {
		std::vector<card> tmp;
		for(int i = 0; i < 7; i++)
			if(p[i]) tmp.push_back(a[i]);
		ret = std::max(ret, eval(tmp));
	} while(next_permutation(p.begin(), p.end()));
	return ret;
}

using namespace std;
int main() {
	while(true) {
		vector<bool> used(52);
		vector<string> s(7);
		vector<card> cards;
		cin >> s[0];
		if(s[0] == "#") return 0;
		for(int i = 1; i < 7; i++) cin >> s[i];
		for(int i = 0; i < 7; i++) {
			cards.push_back(card(s[i]));
			used[cards.back().id()] = true;
		}
		vector<card> at = {cards[0], cards[1], cards[4], cards[5], cards[6]};
		vector<card> bt = {cards[2], cards[3], cards[4], cards[5], cards[6]};
		int cnt = 0, win = 0;
		for(int i = 0; i < 52; i++) {
			if(used[i]) continue;
			for(int j = i + 1; j < 52; j++) {
				if(used[j]) continue;
				cnt++;
				at.push_back(card(i));
				at.push_back(card(j));
				bt.push_back(card(i));
				bt.push_back(card(j));
				win += eval2(at) > eval2(bt);
				for(int k = 0; k < 2; k++) {
					at.pop_back();
					bt.pop_back();
				}
			}
		}
		cout << fixed << setprecision(15) << (double)win / cnt << '\n';
	}
}
accuracy: 1
time_ms: 800
memory_kb: 3396
final_rank: 7

code_snippet: #line 1 "/Users/nok0/Documents/Programming/nok0/cftemp.hpp"
#include <bits/stdc++.h>
using namespace std;

#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)

// name macro
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)

// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}

//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif

// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}
std::vector<std::pair<char, int>> rle(const string &s) {
	int n = s.size();
	std::vector<std::pair<char, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and s[l] == s[r]; r++) {}
		ret.emplace_back(s[l], r - l);
		l = r;
	}
	return ret;
}
template <class T>
std::vector<std::pair<T, int>> rle(const std::vector<T> &v) {
	int n = v.size();
	std::vector<std::pair<T, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and v[l] == v[r]; r++) {}
		ret.emplace_back(v[l], r - l);
		l = r;
	}
	return ret;
}

// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	a = (a % mod + mod) % mod;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}

// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

void main_();

int main() {
	main_();
	return 0;
}
#line 2 "a.cpp"

struct card {
	//S->0, H->1, D->2, C->3
	int suit;
	int rank;
	card() = default;
	card(std::string s) {
		assert(SZ(s) == 2);
		suit = s[0] == 'S' ? 0 : s[0] == 'H' ? 1 : s[0] == 'D' ? 2 : 3;
		rank = s[1] <= '9' ? s[1] - '0' : s[1] == 'T' ? 10 : s[1] == 'J' ? 11 : s[1] == 'Q' ? 12 : s[1] == 'K' ? 13 : 14;
	}
	card(int id) {
		suit = id / 13;
		rank = id % 13 + 2;
	}
	int id() { return suit * 13 + rank - 2; }
	bool operator<(card oth) {
		return rank < oth.rank;
	}
};

std::vector<int> eval(std::vector<card> a) {
	assert(a.size() == 5);
	sort(a.begin(), a.end());
	std::set<int> suits;
	for(const auto &c : a) suits.insert(c.suit);
	if(suits.size() == 1 and a.back().rank - a.front().rank == 4) {
		if(a.back().rank == 14)
			return {9};
		else
			return {8, a.back().rank};
	}
	if(suits.size() == 1 and a.back().rank == 14 and a[3].rank == 5) {
		return {8, 5};
	}
	if(a[0].rank == a[3].rank or a[1].rank == a[4].rank) {
		bool tmp = a[0].rank == a[3].rank;
		return {7, tmp ? a[0].rank : a[4].rank, tmp ? a[4].rank : a[0].rank};
	}
	if((a[0].rank == a[2].rank and a[3].rank == a[4].rank) or (a[2].rank == a[4].rank and a[0].rank == a[1].rank)) {
		bool tmp = a[0].rank == a[2].rank;
		return {6, tmp ? a[0].rank : a[4].rank, tmp ? a[4].rank : a[0].rank};
	}
	if(suits.size() == 1) {
		return {5, a[4].rank, a[3].rank, a[2].rank, a[1].rank, a[0].rank};
	}
	bool straight = true;
	for(int i = 0; i < 4; i++) straight &= a[i + 1].rank - a[i].rank == 1;
	if(straight) { return {4, a[4].rank}; }
	if(a[0].rank == 2 and a[1].rank == 3 and a[2].rank == 4 and a[3].rank == 5 and a[4].rank == 14) {
		return {4, 5};
	}
	if(a[0].rank == a[2].rank) {
		return {3, a[0].rank, a[4].rank, a[3].rank};
	}
	if(a[1].rank == a[3].rank) {
		return {3, a[1].rank, a[4].rank, a[0].rank};
	}
	if(a[2].rank == a[4].rank) {
		return {3, a[2].rank, a[1].rank, a[0].rank};
	}
	if(a[0].rank == a[1].rank) {
		if(a[2].rank == a[3].rank)
			return {2, a[2].rank, a[0].rank, a[4].rank};
		if(a[3].rank == a[4].rank)
			return {2, a[3].rank, a[0].rank, a[2].rank};
	}
	if(a[1].rank == a[2].rank) {
		if(a[3].rank == a[4].rank)
			return {2, a[3].rank, a[1].rank, a[0].rank};
	}
	if(a[0].rank == a[1].rank) {
		return {1, a[0].rank, a[4].rank, a[3].rank, a[2].rank};
	}
	if(a[1].rank == a[2].rank) {
		return {1, a[1].rank, a[4].rank, a[3].rank, a[0].rank};
	}
	if(a[2].rank == a[3].rank) {
		return {1, a[2].rank, a[4].rank, a[1].rank, a[0].rank};
	}
	if(a[3].rank == a[4].rank) {
		return {1, a[3].rank, a[2].rank, a[1].rank, a[0].rank};
	}
	return {0, a[4].rank, a[3].rank, a[2].rank, a[1].rank, a[0].rank};
}

std::vector<int> eval2(std::vector<card> a) {
	assert(a.size() == 7);
	std::vector<int> p{0, 0, 1, 1, 1, 1, 1};
	std::vector<int> ret;
	do {
		std::vector<card> tmp;
		for(int i = 0; i < 7; i++)
			if(p[i]) tmp.push_back(a[i]);
		ret = std::max(ret, eval(tmp));
	} while(next_permutation(all(p)));
	return ret;
}

void main_() {
	while(true) {
		V<> used(52);
		V<string> s(7);
		V<card> cards;
		cin >> s[0];
		if(s[0] == "#") return;
		for(int i = 1; i < 7; i++) cin >> s[i];
		for(int i = 0; i < 7; i++) {
			cards.push_back(card(s[i]));
			used[cards.back().id()] = 1;
		}
		V<card> at = {cards[0], cards[1], cards[4], cards[5], cards[6]};
		V<card> bt = {cards[2], cards[3], cards[4], cards[5], cards[6]};
		int cnt = 0, win = 0;
		REP(i, 52) {
			if(used[i]) continue;
			REP(j, i + 1, 52) {
				if(used[j]) continue;
				cnt++;
				at.push_back(card(i));
				at.push_back(card(j));
				bt.push_back(card(i));
				bt.push_back(card(j));
				win += eval2(at) > eval2(bt);
				REP(_, 2) {
					at.pop_back();
					bt.pop_back();
				}
			}
		}
		print((ld)win / cnt);
	}
}
accuracy: 1
time_ms: 800
memory_kb: 3520
final_rank: 10

code_snippet: #line 1 "a.cpp"
#define _GLIBCXX_DEBUG
#line 1 "/Users/nok0/Documents/Programming/nok0/cftemp.hpp"
#include <bits/stdc++.h>
using namespace std;

#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)

// name macro
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)

// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}

//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif

// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}
std::vector<std::pair<char, int>> rle(const string &s) {
	int n = s.size();
	std::vector<std::pair<char, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and s[l] == s[r]; r++) {}
		ret.emplace_back(s[l], r - l);
		l = r;
	}
	return ret;
}
template <class T>
std::vector<std::pair<T, int>> rle(const std::vector<T> &v) {
	int n = v.size();
	std::vector<std::pair<T, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and v[l] == v[r]; r++) {}
		ret.emplace_back(v[l], r - l);
		l = r;
	}
	return ret;
}

// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	a = (a % mod + mod) % mod;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}

// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

void main_();

int main() {
	main_();
	return 0;
}
#line 3 "a.cpp"

struct trump {
	//s->0, h->1, d->1, c->1
	int suit;
	int val;
	trump() = default;
	trump(std::string s) {
		assert(SZ(s) == 2);
		suit = s[0] == 'S' ? 0 : s[0] == 'H' ? 1 : s[0] == 'D' ? 2 : 3;
		val = s[1] <= '9' ? s[1] - '0' : s[1] == 'T' ? 10 : s[1] == 'J' ? 11 : s[1] == 'Q' ? 12 : s[1] == 'K' ? 13 : 14;
	}
	trump(int id) {
		suit = id / 13;
		val = id % 13 + 2;
	}
	int id() { return suit * 13 + val - 2; }
};

//if a is win return 1
bool compare(array<trump, 5> a, array<trump, 5> b) {
	sort(a.begin(), a.end(), [](trump x, trump y) { return x.val > y.val; });
	sort(b.begin(), b.end(), [](trump x, trump y) { return x.val > y.val; });
	bool a_straight = 1;
	REP(i, 4) {
		if(a[i].val != a[i + 1].val + 1) a_straight = 0;
	}
	int a_st_rank = 0;
	if(a_straight) a_st_rank = a[0].val;
	if(a[0].val == 14 and a[1].val == 5 and a[2].val == 4 and a[3].val == 3 and a[4].val == 2) {
		a_straight = 1;
		a_st_rank = 5;
	}
	bool b_straight = 1;
	REP(i, 4) {
		if(b[i].val != b[i + 1].val + 1) b_straight = 0;
	}
	int b_st_rank = 0;
	if(b_straight) b_st_rank = b[0].val;
	if(b[0].val == 14 and b[1].val == 5 and b[2].val == 4 and b[3].val == 3 and b[4].val == 2) {
		b_straight = 1;
		b_st_rank = 5;
	}

	bool a_flush = 1;
	REP(i, 5) {
		if(a[i].suit != a[0].suit) a_flush = 0;
	}
	bool b_flush = 1;
	REP(i, 5) {
		if(b[i].suit != b[0].suit) b_flush = 0;
	}

	if(a_straight and a_flush) {
		if(b_straight and b_flush) {
			return a_st_rank > b_st_rank;
		} else
			return true;
	}
	if(b_straight and b_flush) {
		return false;
	}

	bool a_four = a[0].val == a[3].val or a[1].val == a[4].val;
	bool b_four = b[0].val == b[3].val or b[1].val == b[4].val;
	if(a_four) {
		if(b_four) {
			int a4 = a[0].val == a[3].val ? a[0].val : a[4].val;
			int a1 = a[0].val == a[3].val ? a[4].val : a[0].val;
			int b4 = b[0].val == b[3].val ? b[0].val : b[4].val;
			int b1 = b[0].val == b[3].val ? b[4].val : b[0].val;
			if(a4 != b4) return a4 > b4;
			return a1 > b1;
		} else
			return true;
	}
	if(b_four) return false;

	bool a_fh = (a[0].val == a[2].val and a[3].val == a[4].val) or (a[2].val == a[4].val and a[0].val == a[1].val);
	bool b_fh = (b[0].val == b[2].val and b[3].val == b[4].val) or (b[2].val == b[4].val and b[0].val == b[1].val);

	if(a_fh) {
		if(b_fh) {
			int a3 = a[0].val == a[2].val ? a[0].val : a[4].val;
			int a2 = a[0].val == a[2].val ? a[4].val : a[0].val;
			int b3 = b[0].val == b[2].val ? b[0].val : b[4].val;
			int b2 = b[0].val == b[2].val ? b[4].val : b[0].val;
			if(a3 != b3) return a3 > b3;
			return a2 > b2;
		} else
			return true;
	}
	if(b_fh) return false;

	if(a_flush) {
		if(b_flush) {
			REP(i, 5) {
				if(a[i].val != b[i].val) return a[i].val > b[i].val;
			}
			return false;
		} else
			return true;
	}
	if(b_flush) return false;

	if(a_straight) {
		if(b_straight) {
			return a_st_rank > b_st_rank;
		} else
			return true;
	}
	if(b_straight) return false;

	bool a_th = (a[0].val == a[2].val) or (a[1].val == a[3].val) or (a[2].val == a[4].val);
	bool b_th = (b[0].val == b[2].val) or (b[1].val == b[3].val) or (b[2].val == b[4].val);
	V<> ac(15), bc(15);
	REP(i, 5) { ac[a[i].val]++, bc[b[i].val]++; }
	if(a_th) {
		if(b_th) {
			int ai = find(all(ac), 3) - ac.begin();
			int bi = find(all(bc), 3) - bc.begin();
			if(ai != bi) return ai > bi;
			reverse(ac.begin(), ac.end());
			reverse(bc.begin(), bc.end());
			return ac > bc;
		} else
			return true;
	}
	if(b_th) return false;

	V<> pa, pb, ai, bi;
	RREP(i, 15) {
		if(ac[i] == 2) pa.pb(i);
		if(bc[i] == 2) pb.pb(i);
		if(ac[i] == 1) ai.pb(i);
		if(bc[i] == 1) bi.pb(i);
	}
	if(SZ(pa) == 2) {
		if(SZ(pb) < 2) return true;
		if(pa[0] != pb[0]) return pa[0] > pb[0];
		if(pa[1] != pb[1]) return pa[1] > pb[1];
		return ai[0] > bi[0];
	}
	if(SZ(pb) == 2) return false;
	if(SZ(pa) == 1) {
		if(SZ(pb) < 1) return true;
		if(pa[0] != pb[0]) return pa[0] > pb[0];
		REP(i, 3) {
			if(ai[i] != bi[i]) return ai[i] > bi[i];
		}
		return false;
	}
	if(SZ(pb) == 1) return false;
	REP(i, 5) {
		if(a[i].val != b[i].val) return a[i].val > b[i].val;
	}
	return false;
}

void main_() {
	while(true) {
		V<trump> at, bt;
		STR(s1);
		if(s1 == "#") return;
		at.push_back(trump(s1));
		STR(s2);
		at.push_back(trump(s2));
		REP(_, 2) {
			STR(s);
			bt.push_back(trump(s));
		}
		REP(_, 3) {
			STR(s);
			at.push_back(trump(s));
			bt.push_back(trump(s));
		}
		V<> used(52);
		foa(v, at) used[v.id()] = 1;
		foa(v, bt) used[v.id()] = 1;
		int cnt = 0, win = 0;
		REP(i, 52) {
			if(used[i]) continue;
			REP(j, i + 1, 52) {
				if(used[j]) continue;
				at.push_back(trump(i));
				at.push_back(trump(j));
				bt.push_back(trump(i));
				bt.push_back(trump(j));
				cnt++;
				array<trump, 5> a_strongest = {at[0], at[1], at[2], at[3], at[4]};

				REP(k, 7) {
					REP(l, k + 1, 7) {
						array<trump, 5> tmp;
						int now = 0;
						REP(id, 7) {
							if(id == k or id == l) continue;
							tmp[now++] = at[id];
						}
						if(compare(tmp, a_strongest)) a_strongest = tmp;
					}
				}

				array<trump, 5> b_strongest = {bt[0], bt[1], bt[2], bt[3], bt[4]};
				REP(k, 7) {
					REP(l, k + 1, 7) {
						array<trump, 5> tmp;
						int now = 0;
						REP(id, 7) {
							if(id == k or id == l) continue;
							tmp[now++] = bt[id];
						}
						if(compare(tmp, b_strongest)) b_strongest = tmp;
					}
				}

				if(compare(a_strongest, b_strongest)) win++;

				REP(_, 2) {
					at.pop_back();
					bt.pop_back();
				}
			}
		}
		print((ld)win / cnt);
	}
}
accuracy: 1
time_ms: 1360
memory_kb: 3472
final_rank: 13

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

pair<int,int> solve(string S) {
    int f = 0;
    for(int i = 0; i < 4; i++) {
        if("SHDC"[i] == S[0]) {
            f = i;
        }
    }
    int s = S[1]-'0';
    for(int i = 0; i < 5; i++) {
        if(S[1] == "TJQKA"[i]) {
            s = i+10;
        }
    }
    return {f,s};
}

pair<int,int> score(vector<pair<int,int>>tmp) {
    int f = -1,s = 0;
    if(f == -1) {
        bool flag = true;
        for(int i = 0; i < 5; i++) {
            if(tmp[i].first != i+10) {
                flag = false;
            }
            if(i) {
                if(tmp[i].second != tmp[i-1].second) {
                    flag = false;
                }
            }
        }
        if(flag) {
            f = 10;
        }
    }
    vector<int>sum(15);
    for(int i = 0; i < tmp.size(); i++) {
        sum[tmp[i].first]++;
        if(tmp[i].first == 14) {
            sum[1]++;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false;
        for(int i = 1; i <= 10; i++) {
            bool flag2 = true;
            for(int j = 0; j < 5; j++) {
                if(sum[i+j] == 0) {
                    flag2 = false;
                }
            }
            if(flag2) {
                flag = true;
                s = i+4;
            }
        }
        for(int i = 0; i < 5; i++) {
            if(i) {
                if(tmp[i].second != tmp[i-1].second) {
                    flag = false;
                }
            }
        }
        if(flag) {
            f = 9;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false;
        int ss = 0;
        for(int i = 1; i < 15; i++) {
            if(sum[i] == 4) {
                flag = true;
                s = i;
            }
            if(sum[i] == 1) {
                ss = i;
            }
        }
        if(flag) {
            f = 8;
            s = s*15+ss;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false,flag2 = false;
        int ss = 0;
        for(int i = 1; i < 15; i++) {
            if(sum[i] == 3) {
                flag = true;
                s = i;
            }
            if(sum[i] == 2) {
                flag2 = true;
                ss = i;
            }
        }
        if(flag && flag2) {
            f = 7;
            s = s*15+ss;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = true;
        for(int i = 0; i < 5; i++) {
            s += tmp[i].first*pow(15,i);
            if(i) {
                if(tmp[i].second != tmp[i-1].second) {
                    flag = false;
                }
            }
        }
        if(flag) {
            f = 6;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false;
        for(int i = 1; i <= 10; i++) {
            bool flag2 = true;
            for(int j = 0; j < 5; j++) {
                if(sum[i+j] == 0) {
                    flag2 = false;
                }
            }
            if(flag2) {
                flag = true;
                s = i+4;
            }
        }
        if(flag) {
            f = 5;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false;
        int ss = 0,sss = 0;
        for(int i = 2; i < 15; i++) {
            if(sum[i] == 3) {
                flag = true;
                s = i;
            }
            else if(sum[i] == 1) {
                if(sss != 0) {
                    ss = i;
                }
                else {
                    sss = i;
                }
            }
        }
        if(flag) {
            f = 4;
            s = s*15*15+ss*15+sss;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false;
        int ss = 0,sss = 0;
        for(int i = 2; i < 15; i++) {
            if(sum[i] == 2) {
                flag = true;
                if(ss != 0) {
                    s = i;
                }
                else {
                    ss = i;
                }
            }
            else if(sum[i] == 1) {
                sss = i;
            }
        }
        if(flag && s && ss && sss) {
            f = 3;
            s = s*15*15+ss*15+sss;
        }
    }
    if(f == -1) {
        s = 0;
        bool flag = false;
        int ss = 0,sss = 0,ssss = 0;
        for(int i = 2; i < 15; i++) {
            if(sum[i] == 2) {
                flag = true;
                s = i;
            }
            else if(sum[i] == 1) {
                if(sss != 0) {
                    ss = i;
                }
                else if(ssss != 0) {
                    sss = i;
                }
                else {
                    ssss = i;
                }
            }
        }
        if(flag && ss && sss && ssss) {
            f = 2;
            s = s*15*15*15+ss*15*15+sss*15+ssss;
        }
    }
    if(f == -1) {
        f = 1;
        s = 0;
        for(int i = 0; i < 5; i++) {
            s += pow(15,i)*tmp[i].first;
        }
    }
    return {f,s};
}

int main() {
    cout << fixed << setprecision(18);
    while (true) {
        string Y1,Y2,O1,O2,C1,C2,C3;
        cin >> Y1;
        if(Y1 == "#") {
            return 0;
        }
        cin >> Y2 >> O1 >> O2 >> C1 >> C2 >> C3;
        vector<pair<int,int>>tmp1,tmp2;
        tmp1.push_back(solve(Y1));
        tmp1.push_back(solve(Y2));
        tmp2.push_back(solve(O1));
        tmp2.push_back(solve(O2));
        tmp1.push_back(solve(C1));
        tmp1.push_back(solve(C2));
        tmp1.push_back(solve(C3));
        tmp2.push_back(solve(C1));
        tmp2.push_back(solve(C2));
        tmp2.push_back(solve(C3));
        double zans1 = 0,zans2 = 0;
        for(int i = 0; i < 4; i++) {
            for(int j = 2; j < 15; j++) {
                for(int k = 0; k < 4; k++) {
                    for(int l = 2; l < 15; l++) {
                        pair<int,int> C4 = {i,j},C5 = {k,l};
                        if(C4 == C5) {
                            continue;
                        }
                        bool flag = true;
                        for(int m = 0; m < tmp1.size(); m++) {
                            if(tmp1[m] == C4 || tmp1[m] == C5) {
                                flag = false;
                            }
                        }
                        for(int m = 0; m < tmp2.size(); m++) {
                            if(tmp2[m] == C4 || tmp2[m] == C5) {
                                flag = false;
                            }
                        }
                        if(!flag) {
                            continue;
                        }
                        vector<pair<int,int>>tmp3 = tmp1;
                        vector<pair<int,int>>tmp4 = tmp2;
                        tmp3.push_back(C4);
                        tmp3.push_back(C5);
                        tmp4.push_back(C4);
                        tmp4.push_back(C5);
                        for(int m = 0; m < tmp3.size(); m++) {
                            swap(tmp3[m].first,tmp3[m].second);
                        }
                        for(int m = 0; m < tmp4.size(); m++) {
                            swap(tmp4[m].first,tmp4[m].second);
                        }
                        sort(tmp3.begin(),tmp3.end());
                        sort(tmp4.begin(),tmp4.end());
                        pair<int,int> x,y;
                        for(int m = 0; m < 7; m++) {
                            for(int n = m+1; n < 7; n++) {
                                vector<pair<int,int>>tmp5;
                                for(int o = 0; o < tmp3.size(); o++) {
                                    if(o != m && o != n) {
                                        tmp5.push_back(tmp3[o]);
                                    }
                                }
                                x = max(x,score(tmp5));
                            }
                        }
                        for(int m = 0; m < 7; m++) {
                            for(int n = m+1; n < 7; n++) {
                                vector<pair<int,int>>tmp5;
                                for(int o = 0; o < tmp4.size(); o++) {
                                    if(o != m && o != n) {
                                        tmp5.push_back(tmp4[o]);
                                    }
                                }
                                y = max(y,score(tmp5));
                            }
                        }
                        zans1++;
                        if(x > y) {
                            zans2++;
                        }
                    }
                }
            }
        }
        cout << zans2/zans1 << endl;
    }
}
accuracy: 1
time_ms: 3010
memory_kb: 3700
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct card{
  char suit;
  int rank;
  card(){
  }
  card(string S){
    suit = S[0];
    if (S[1] == 'A'){
      rank = 14;
    } else if (S[1] == 'K'){
      rank = 13;
    } else if (S[1] == 'Q'){
      rank = 12;
    } else if (S[1] == 'J'){
      rank = 11;
    } else if (S[1] == 'T'){
      rank = 10;
    } else {
      rank = S[1] - '0';
    }
  }
  bool operator <(card C){
    return rank < C.rank || rank == C.rank && suit < C.suit;
  }
};
vector<int> hand(vector<card> C){
  sort(C.begin(), C.end());
  set<char> suits;
  for (int i = 0; i < 5; i++){
    suits.insert(C[i].suit);
  }
  if (suits.size() == 1 && C[4].rank - C[0].rank == 4){
    if (C[4].rank == 14){
      return vector<int>{9};
    } else {
      return vector<int>{8, C[4].rank};
    }
  }
  if (suits.size() == 1 && C[3].rank == 5 && C[4].rank == 14){
    return vector<int>{8, 5};
  }
  if (C[0].rank == C[3].rank){
    return vector<int>{7, C[0].rank, C[4].rank};
  }
  if (C[1].rank == C[4].rank){
    return vector<int>{7, C[1].rank, C[0].rank};
  }
  if (C[0].rank == C[2].rank && C[3].rank == C[4].rank){
    return vector<int>{6, C[0].rank, C[3].rank};
  }
  if (C[2].rank == C[4].rank && C[0].rank == C[1].rank){
    return vector<int>{6, C[2].rank, C[0].rank};
  }
  if (suits.size() == 1){
    return vector<int>{5, C[4].rank, C[3].rank, C[2].rank, C[1].rank, C[0].rank};
  }
  if (C[1].rank - C[0].rank == 1 && C[2].rank - C[1].rank == 1 && C[3].rank - C[2].rank == 1 && C[4].rank - C[3].rank == 1){
    return vector<int>{4, C[4].rank};
  }
  if (C[0].rank == 2 && C[1].rank == 3 && C[2].rank == 4 && C[3].rank == 5 && C[4].rank == 14){
    return vector<int>{4, 5};
  }
  if (C[0].rank == C[2].rank){
    return vector<int>{3, C[0].rank, C[4].rank, C[3].rank};
  }
  if (C[1].rank == C[3].rank){
    return vector<int>{3, C[1].rank, C[4].rank, C[0].rank};
  }
  if (C[2].rank == C[4].rank){
    return vector<int>{3, C[2].rank, C[1].rank, C[0].rank};
  }
  if (C[0].rank == C[1].rank && C[2].rank == C[3].rank){
    return vector<int>{2, C[2].rank, C[0].rank, C[4].rank};
  }
  if (C[0].rank == C[1].rank && C[3].rank == C[4].rank){
    return vector<int>{2, C[3].rank, C[0].rank, C[2].rank};
  }
  if (C[1].rank == C[2].rank && C[3].rank == C[4].rank){
    return vector<int>{2, C[3].rank, C[1].rank, C[0].rank};
  }
  if (C[0].rank == C[1].rank){
    return vector<int>{1, C[0].rank, C[4].rank, C[3].rank, C[2].rank};
  }
  if (C[1].rank == C[2].rank){
    return vector<int>{1, C[1].rank, C[4].rank, C[3].rank, C[0].rank};
  }
  if (C[2].rank == C[3].rank){
    return vector<int>{1, C[2].rank, C[4].rank, C[1].rank, C[0].rank};
  }
  if (C[3].rank == C[4].rank){
    return vector<int>{1, C[3].rank, C[2].rank, C[1].rank, C[0].rank};
  }
  return vector<int>{0, C[4].rank, C[3].rank, C[2].rank, C[1].rank, C[0].rank};
}
vector<int> hand2(vector<card> C){
  vector<int> ans;
  vector<int> p = {0, 0, 1, 1, 1, 1, 1};
  while (true){
    vector<card> C2;
    for (int i = 0; i < 7; i++){
      if (p[i] == 1){
        C2.push_back(C[i]);
      }
    }
    ans = max(ans, hand(C2));
    if (!next_permutation(p.begin(), p.end())){
      break;
    }
  }
  return ans;
}
int main(){
  cout << fixed << setprecision(20);
  while (true){
    vector<string> S(7);
    cin >> S[0];
    if (S[0] == "#"){
      break;
    }
    for (int i = 1; i < 7; i++){
      cin >> S[i];
    }
    vector<card> C(9);
    for (int i = 0; i < 7; i++){
      C[i] = card(S[i]);
    }
    string suits = "SHDC";
    int cnt1 = 0, cnt2 = 0;
    for (int s1 = 0; s1 < 4; s1++){
      for (int r1 = 2; r1 <= 14; r1++){
        for (int s2 = 0; s2 < 4; s2++){
          for (int r2 = 2; r2 <= 14; r2++){
            C[7].suit = suits[s1];
            C[7].rank = r1;
            C[8].suit = suits[s2];
            C[8].rank = r2;
            bool ok = true;
            for (int i = 0; i < 9; i++){
              for (int j = i + 1; j < 9; j++){
                if (C[i].suit == C[j].suit && C[i].rank == C[j].rank){
                  ok = false;
                }
              }
            }
            if (ok){
              vector<card> A = {C[0], C[1], C[4], C[5], C[6], C[7], C[8]};
              vector<card> B = {C[2], C[3], C[4], C[5], C[6], C[7], C[8]};
              if (hand2(A) > hand2(B)){
                cnt1++;
              }
              cnt2++;
            }
          }
        }
      }
    }
    cout << (double) cnt1 / cnt2 << endl;
  }
}
accuracy: 1
time_ms: 2780
memory_kb: 3160
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=15;
const int INF=1<<30;
//const ll INF=1LL<<60;

ll p10[23];

string A="SHDC",B="AKQJT98765432A";

ll MA[100];

ll dp[2][53][53],half[2][53],al[2];

ll score(vector<string> &X){
    
    {
        bool ok=true;
        int j=13-MA[X[0][1]-'0'];
        for(int i=0;i<5;i++){
            if(i+1<5&&X[i][0]!=X[i+1][0]) ok=false;
            if(j>=10){
                ok=false;
                break;
            }
            if(X[i][1]!=B[i+j]) ok=false;
            if(!ok) break;
        }
        if(ok) return p10[18]+(10-j);
    }
    //(ロイヤル)ストレートフラッシュ
    
    {
        bool ok=true;
        for(int i=0;i+1<4;i++){
            if(X[i][1]!=X[i+1][1]) ok=false;
            if(!ok) break;
        }
        if(ok) return p10[17]+MA[X[0][1]-'0']*100+MA[X[4][1]-'0'];
    }
    //フォーカード
    
    {
        bool ok=true;
        for(int i=0;i+1<3;i++) if(X[i][1]!=X[i+1][1]) ok=false;
        if(X[3][1]!=X[4][1]) ok=false;
        if(ok) return p10[16]+MA[X[0][1]-'0']*100+MA[X[3][1]-'0'];
    }
    //フルハウス
    
    {
        bool ok=true;
        for(int i=0;i+1<5;i++){
            if(X[i][0]!=X[i+1][0]) ok=false;
            if(!ok) break;
        }
        if(ok){
            ll res=p10[15];
            for(int i=0;i<5;i++) res+=MA[X[i][1]-'0']*p10[(4-i)*2];
            return res;
        }
    }
    //フラッシュ
    
    {
        bool ok=true;
        int j=13-MA[X[0][1]-'0'];
        for(int i=0;i<5;i++){
            if(j>=10){
                ok=false;
                break;
            }
            if(X[i][1]!=B[i+j]) ok=false;
            if(!ok) break;
        }
        if(ok) return p10[14]+(10-j);
    }
    //ストレート
    
    {
        bool ok=true;
        for(int i=0;i+1<3;i++) if(X[i][1]!=X[i+1][1]) ok=false;
        if(ok){
            ll res=p10[13];
            res+=MA[X[0][1]-'0']*10000;
            res+=MA[X[3][1]-'0']*100;
            res+=MA[X[4][1]-'0'];
            return res;
        }
    }
    //スリーカード
    
    {
        bool ok=true;
        if(X[0][1]!=X[1][1]) ok=false;
        if(X[2][1]!=X[3][1]) ok=false;
        
        if(ok){
            ll res=p10[12];
            res+=MA[X[0][1]-'0']*10000;
            res+=MA[X[2][1]-'0']*100;
            res+=MA[X[4][1]-'0'];
            return res;
        }
    }
    //ツーペア
    
    {
        bool ok=true;
        if(X[0][1]!=X[1][1]) ok=false;
        
        if(ok){
            ll res=p10[11];
            res+=MA[X[0][1]-'0']*1000000;
            res+=MA[X[2][1]-'0']*10000;
            res+=MA[X[3][1]-'0']*100;
            res+=MA[X[4][1]-'0'];
            return res;
        }
    }
    //ワンペア
    
    ll res=0;
    for(int i=0;i<5;i++) res+=MA[X[i][1]-'0']*p10[(4-i)*2];
    return res;
}

vector<string> card;

void solve(vector<string> &X,bool wh){
    vector<int> id={0,1,2,3,4,5,5};
    vector<string> Y(5);
    do{
        int a=-1,b=-1;
        for(int i=0;i<7;i++){
            if(id[i]<5){
                if(i<5) Y[id[i]]=X[i];
                if(i==5) a=id[i];
                if(i==6) b=id[i];
            }
        }
        if(a!=-1){
            if(b!=-1){
                for(int i=0;i<si(card);i++){
                    for(int j=i+1;j<si(card);j++){
                        Y[a]=card[i];
                        Y[b]=card[j];
                        ll c=score(Y);
                        
                        chmax(dp[wh][i][j],c);
                        chmax(dp[wh][j][i],c);
                    }
                }
            }else{
                for(int i=0;i<si(card);i++){
                    Y[a]=card[i];
                    ll c=score(Y);
                    
                    chmax(half[wh][i],c);
                }
            }
        }else{
            if(b==-1){
                ll c=score(Y);
                
                chmax(al[wh],c);
            }
        }
    }while(next_permutation(all(id)));
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    p10[0]=1;
    for(int i=1;i<=18;i++) p10[i]=p10[i-1]*10;
    
    for(int i=0;i<13;i++) MA[int(B[i]-'0')]=13-i;
    
    while(1){
        vector<string> S(7),C,D;
        for(int i=0;i<7;i++) cin>>S[i];
        if(S[0]=="#") break;
        card.clear();
        
        for(int i=0;i<4;i++){
            for(int j=0;j<13;j++){
                string U;
                U+=A[i];
                U+=B[j];
                bool check=true;
                for(int k=0;k<7;k++){
                    if(U==S[k]) check=false;
                    if(!check) break;
                }
                if(check) card.push_back(U);
            }
        }
        
        //cout<<si(card)<<endl;
        
        C={S[0],S[1],S[4],S[5],S[6]};
        D={S[2],S[3],S[4],S[5],S[6]};
        
        memset(dp,0,sizeof(dp));
        memset(half,0,sizeof(half));
        al[0]=al[1]=0;
        
        solve(C,0);
        solve(D,1);
        
        for(int i=0;i<si(card);i++){
            for(int j=0;j<si(card);j++){
                if(i==j) continue;
                chmax(dp[0][i][j],half[0][i]);
                chmax(dp[1][i][j],half[1][i]);
                chmax(dp[0][j][i],half[0][i]);
                chmax(dp[1][j][i],half[1][i]);
                chmax(dp[0][i][j],al[0]);
                chmax(dp[1][i][j],al[1]);
            }
        }
        
        int win=0;
        
        for(int i=0;i<si(card);i++){
            for(int j=i+1;j<si(card);j++){
                if(dp[0][i][j]>dp[1][i][j]) win++;
            }
        }
        
        cout<<setprecision(25)<<double(win)/double(45*44/2)<<endl;
    }
    
}
accuracy: 1
time_ms: 4610
memory_kb: 3468
final_rank: 20