func_code_string: #include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, int> a, pair<int, int> b) {     return (a.first == b.first) ? a.second < b.second : a.first < b.first;   }   long long int modInverse(long long int a) {     long long int m = 1000000007;     long long int y = 0, x = 1;     while (a > 1) {       long long int q = a / m;       long long int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += 1000000007;     return x;   }   long long int binpow(long long int a, long long int p) {     if (p == 0) return 1;     long long int ret = binpow(a, p / 2);     ret *= ret;     ret %= 1000000007;     if (p % 2) {       ret *= a;       ret %= 1000000007;     }     return ret;   }   int f[54][54][54][54];   char a[100], b[100];   int n;   bool check(int x, int y) { return (a[x] == a[y] || b[x] == b[y]); }   int dfs(int i, int j, int l, int r) {     if (f[i][j][l][r]) return 0;     if (i == 3) return check(j, r) && check(l, r);     if (check(l, r))       if (dfs(i - 1, i - 3, j, r)) return 1;     if (check(i - 3, r))       if (dfs(i - 1, r, j, l)) return 1;     f[i][j][l][r] = 1;     return 0;   }   void solve() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];     if (n == 1 || dfs(n, n - 2, n - 1, n))       cout <<  YES ;     else       cout <<  NO ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }   }   