#include #include #include #include //#include using namespace std; //8 2C 2D 3D 4D 5D 3H 4H 5S #define FOR(i,n) for(int i=0;i=1 || cnt[2]==0) { if (x>=0 || cnt[1]==0) { solved=true; return; } } } else { FOR(i,13) { if (difs[x][i]) { bool changed=false; if (cnt[p[x+1]] > 1 && difs[x+1][i]) { difs[x+1][i]=false; changed=true; } tr(x+1); if (changed) difs[x+1][i]=true; } } } } int last=0; void tr2(int x) { if (x==4) { solved=true; return; } else { FOR(i,13) { if (difs2[x][i]) { if (x != 1) { bool changed=false; if (cnt[p2[x+1]] > 1 && difs2[x+1][i]) { difs2[x+1][i]=false; changed=true; } if (x==0) last=i; tr2(x+1); if (changed) difs2[x+1][i]=true; } else { //zkusim primo if (i==last) { difs2[x+1][i]=false; cnt[p2[1]]--; bool changed=false; if (difs2[3][i]) { changed = true; difs2[3][i]=false; } tr2(x+1); cnt[p2[1]]++; difs2[x+1][i]=true; if (changed) difs2[3][i]=true; } //zkusim neprimo else { int u = last; difs2[x+1][i]=false; int temp = cnt[p2[1]]; cnt[p2[1]]=1; bool changed=false; if (difs2[3][i]) { changed = true; difs2[3][i]=false; } tr2(x+1); cnt[p2[1]] = temp; difs2[x+1][i]=true; if (changed) difs2[3][i]=true; } } } } } } void solve() { //1234 FOR(i,3){ FOR(j,13){ difs[i][j]=false; } } FOR(i,3) { FOR(j, 13) { if (used[i][j] && used[i+1][j]) difs[i][j]=true; } } tr(0); if (solved) return; //12324 FOR(i,4){ FOR(j,13){ difs2[i][j]=false; } } FOR(i,2) { FOR(j, 13) { if (used[i][j] && used[i+1][j]) difs2[i][j]=true; } } FOR(j, 13) { if (used[2][j] && used[1][j]) difs2[2][j]=true; } FOR(j, 13) { if (used[1][j] && used[3][j]) difs2[3][j]=true; } tr2(0); } int main() { ios::sync_with_stdio(false); int n, m ,k; while (cin>>n) { if (n>37) { cout << "YES" << endl; } solved=false; FOR(i,4) { cnt[i]=0; FOR(j,13) used[i][j] = false; } FOR(i,n) { string s; cin >> s; int x, y; //value if (s[0] >= '2' && s[0] <= '9' ) y=s[0] - '0'; else if (s[0] == 'A') y=1; else if (s[0] == 'X') y=10; else if (s[0] == 'J') y=11; else if (s[0] == 'Q') y=12; else if (s[0] == 'K') y=0; //color if (s[1] == 'C') x=0; else if (s[1] == 'D') x=1; else if (s[1] == 'H') x=2; else if (s[1] == 'S') x=3; used[x][y]=true; cnt[x]++; } //alg bool row[4]; FOR(i,4) { row[i]=false; //p[i]=0; } FOR(i,4) { p[0]=i; p2[0]=i; row[i]=true; FOR(j,4) { if (row[j]) continue; p[1]=j; p2[1]=j; p2[4]=j; row[j]=true; FOR(k,4) { if (row[k]) continue; p[2]=k; p2[2]=k; row[k]=true; FOR(l,4) { if (row[l]) continue; p[3]=l; p2[3]=l; solve(); if (solved) break; } row[k]=false; if (solved) break; } row[j]=false; if (solved) break; } row[i]=false; if (solved) break; } if (solved) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }