#include <stdio.h>
#include <stdlib.h>
int hraci;
int barva_stul[5];
int hodnota_stul[5];
int barva[2 * 10];
int hodnota[2 * 10];
int hodnoceni_high[10];
int hodnoceni_low[10];
int maxhigh, maxlow;
int rozhodni(int* tabulka, int p)
{
int i, j;
int counter;
int postupka = 0;
int dvojice = 0, trojice = 0, ctverice = 0;
int vicparu = 0;
int karta = 0;
int full_tri = 0, full_dva = 0;
int flush = 0;
int fullhouse = 0;
int royal_flush = 0;
counter = 0;
for (i = 1; i <= 14; i++)
{
if (tabulka[4 * 16 + i])
counter++;
else
counter = 0;
if (counter >= 5)
postupka = i;
}
for (i = 1; i <= 14; i++)
{
if (tabulka[4 * 16 + i] >= 2)
{
if (dvojice)
vicparu++;
dvojice += i;
}
if (tabulka[4 * 16 + i] >= 3)
trojice += i;
if (tabulka[4 * 16 + i] >= 4)
ctverice += i;
karta += i;
}
hodnoceni_low[p] = karta + 16 * dvojice + 16 * 16 * vicparu + 16 * 16 * 16 * trojice
+ 16 * 16* 16*16 * postupka;
for (j = 0; j < 4; j++)
{
if (tabulka[j * 16 + 15] >= 5)
flush++;
}
for (i = 1; i <= 14; i++)
{
if (tabulka[4 * 16 + i] == 3)
full_tri = i;
if (tabulka[4 * 16 + i] == 2)
full_dva = i;
}
fullhouse = full_dva ? full_tri : 0;
if (postupka)
{
for (j = 0; j < 4; j++)
{
royal_flush = postupka;
for (i = postupka; i >= postupka - 5; i--)
{
if (tabulka[j * 16 + i] == 0)
royal_flush = 0;
}
if (royal_flush)
break;
}
}
hodnoceni_high[i] = flush + 16 * fullhouse + 16 * 16 * ctverice + 16*16*16 * royal_flush;
return 0;
}
int ohodnot(int p)
{
int i;
int j;
int tabulka[5 * 16];
memset(tabulka
, 0, 5 * 16 * sizeof(int));
for (i = 0; i < 5; i++)
{
tabulka[16 * barva_stul[i] + hodnota_stul[i]]++;
if (hodnota_stul[i] == 14)
{
tabulka[16 * barva_stul[i] + 1]++;
}
}
for (i = p * 2; i <= p * 2 + 1; i++)
{
tabulka[16 * barva[i] + hodnota[i]]++;
if (hodnota[i] == 14)
{
tabulka[16 * barva[i] + 1]++;
}
}
for (i = 2; i <= 14; i++)
for (j = 0; j < 4; j++)
tabulka[16 * 4 + i] += tabulka[16 * j + i];
for (j = 0; j < 4; j++)
for (i = 2; i <= 14; i++)
tabulka[16 * j + 15] += tabulka[16 * j + i];
rozhodni(tabulka, p);
/* */
/*
printf("\n");
printf("\n");
for (j = 0; j < 5; j++)
{
for (i = 0; i < 16; i++)
printf("%d", tabulka[16 * j + i]);
printf("\n");
}
*/
}
int nactikartu(int* bar, int* hod)
{
char s[4];
if (s[0] >= '0' && s[0] <= '9')
*hod = s[0] - '0';
else switch (s[0])
{
case 'X': *hod = 10;break;
case 'J': *hod = 11;break;
case 'Q': *hod = 12;break;
case 'K': *hod = 13;break;
case 'A': *hod = 14;break;
default:;
}
switch (s[1])
{
case 'c': *bar = 0;break;
case 'd': *bar = 1;break;
case 'h': *bar = 2;break;
case 's': *bar = 3;break;
default:;
}
/* printf("%d %d =", *bar, *hod);*/
return 0;
}
int main(int argc, char *argv[])
{
int i;
int mezera = 0;
while (scanf("%d", &hraci
) == 1) {
for (i = 0; i < 5; i++)
nactikartu(barva_stul + i, hodnota_stul + i);
for (i = 0; i < hraci * 2; i++)
{
nactikartu(barva + i, hodnota + i);
}
for (i = 0; i < hraci; i++)
{
ohodnot(i);
}
maxhigh = 0;
maxlow = 0;
for (i = 0; i < hraci; i++)
{
if (hodnoceni_high[i] > maxhigh)
{
if (hodnoceni_low[i] > maxlow)
{
maxlow = hodnoceni_low[i];
maxhigh = hodnoceni_high[i];
}
}
}
for (i = 0; i < hraci; i++)
{
if (hodnoceni_high[i] == maxhigh)
{
if (hodnoceni_low[i] == maxlow)
{
if (mezera)
mezera = 1;
}
}
}
}
return 0;
}