#include<cstdio>
#include<iostream>
using namespace std;
int n, num[20];
char a,b,c;
int charToInt(char x) {
int ret = 0;
if (x>='2' && x<='9') ret = x - '0';
else if (x == 'J' || x == 'Q' || x == 'K' || x == 'T') ret = 10;
else ret = 11;
return ret;
}
int main()
{
freopen("jack0.in","r",stdin);
freopen("jack0.out","w",stdout);
cin>>n;
for (int i=1; i<10; i++) num[i] = n * 4;
num[10] = n * 16;
cin>>a>>b>>c;
int ra = charToInt(a), rb = charToInt(b), rc = charToInt(c);
int myScore = rb + rc;
if (myScore == 22) myScore = 12;
if (ra == 11) num[1]--; else num[ra]--;
if (rb == 11) num[1]--; else num[rb]--;
if (rc == 11) num[1]--; else num[rc]--;
double sum = 0, win = 0;
for (int i=1; i<=10; i++) {
int hisScore = ra;
if (i == 1) hisScore += 11; else hisScore += i;
if (hisScore == 22) hisScore = 12;
if (myScore > hisScore) win+=num[i];
sum+=num[i];
}
double ans = win / sum;
printf("%.5lf\n",ans);
}