func_code_string: #include <bits/stdc++.h>   using namespace std;   const long maxn = 60;   const char spec1[5] = { T ,  J ,  Q ,  K ,  A };   const char spec2[4] = { S ,  D ,  H ,  C };   long start[maxn];   bool pos[maxn][maxn][maxn][maxn];   long n;   bool ispair[maxn][maxn];   int main() {     scanf( %ld , &n);     long q;     long maxx = -1;     for (q = 1; q <= n; q++) {       long tmp1 = -1;       long tmp2 = -1;       string s;       cin >> s;       if ((s[0] >=  2 ) && (s[0] <=  9 ))         tmp1 = s[0] -  2 ;       else {         for (long j = 0; j <= 4; j++)           if (spec1[j] == s[0]) {             tmp1 = j + 8;             break;           }       }       for (long j = 0; j <= 3; j++)         if (spec2[j] == s[1]) {           tmp2 = j;           break;         }       assert(tmp1 != -1);       assert(tmp2 != -1);       start[q] = tmp2 * 13 + tmp1 + 1;       maxx = max(maxx, start[q]);     }     for (long first = 1; first <= 52; first++)       for (long second = 1; second <= 52; second++) {         long t1 = (first - 1) % 13;         long t2 = (first - 1) / 13;         long t3 = (second - 1) % 13;         long t4 = (second - 1) / 13;         ispair[first][second] = ((t1 == t3) || (t2 == t4));       }     long t1, t2, t3;     if (n >= 3)       t1 = start[n - 2];     else       t1 = 0;     if (n >= 2)       t2 = start[n - 1];     else       t2 = 0;     t3 = start[n];     pos[n][t1][t2][t3] = true;     for (long it = n; it > 1; it--)       for (long first = 0; first <= maxx; first++)         for (long second = 0; second <= maxx; second++)           for (long third = 0; third <= maxx; third++)             if (pos[it][first][second][third]) {               if (ispair[second][third]) {                 long tmp;                 if (it - 3 > 0)                   tmp = start[it - 3];                 else                   tmp = 0;                 pos[it - 1][tmp][first][third] = true;               }               if ((it - 3 > 0) && (ispair[start[it - 3]][third]))                 pos[it - 1][third][first][second] = true;             }     for (long j = 0; j <= maxx; j++)       if (pos[1][0][0][j]) {         printf( YES n );         exit(0);       }     printf( NO n );   }   