func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, i;   vector<string> pos;   string s;   set<vector<string> > st;   set<vector<string> >::iterator iter;   bool srch(vector<string> pos) {     if (pos.size() == 1) return true;     iter = st.find(pos);     if (iter != st.end()) return false;     int x = pos.size() - 1;     if (pos.size() >= 4) {       if (pos[x][0] == pos[x - 3][0] || pos[x][1] == pos[x - 3][1]) {         vector<string> nv = pos;         nv[x - 3] = nv[x];         nv.pop_back();         if (srch(nv)) return true;         st.insert(nv);       }     }     if (pos[x][0] == pos[x - 1][0] || pos[x][1] == pos[x - 1][1]) {       vector<string> nv = pos;       nv[x - 1] = nv[x];       nv.pop_back();       if (srch(nv)) return true;       st.insert(nv);     }     return false;   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> s;       pos.push_back(s);     }     if (srch(pos))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }   