malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int n, m;   char s[2020][2020];   int dp[2020][2020], a[2020][2020][2], dp1[2020][2020];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , s[i]);       for (int j = 0; j < m; ++j) {         if (j == 0) {           a[i][j][0] = 0;         } else {           if (s[i][j] == s[i][j - 1]) {             a[i][j][0] = a[i][j - 1][0] + 1;           } else {             a[i][j][0] = 0;           }         }       }       for (int j = m - 1; j >= 0; --j) {         if (j == m - 1) {           a[i][j][1] = 0;         } else {           if (s[i][j] == s[i][j + 1]) {             a[i][j][1] = a[i][j + 1][1] + 1;           } else {             a[i][j][1] = 0;           }         }       }       if (i == 0) {         for (int j = 0; j < m; ++j) {           dp[i][j] = 0;         }       } else {         for (int j = 0; j < m; ++j) {           if (s[i - 1][j] == s[i][j])             dp[i][j] = min(dp[i - 1][j] + 1, min(a[i][j][0], a[i][j][1]));           else             dp[i][j] = 0;         }       }     }     for (int i = n - 1; i >= 0; --i) {       for (int j = 0; j < m; ++j) {         if (j == 0) {           a[i][j][0] = 0;         } else {           if (s[i][j] == s[i][j - 1]) {             a[i][j][0] = a[i][j - 1][0] + 1;           } else {             a[i][j][0] = 0;           }         }       }       for (int j = m - 1; j >= 0; --j) {         if (j == m - 1) {           a[i][j][1] = 0;         } else {           if (s[i][j] == s[i][j + 1]) {             a[i][j][1] = a[i][j + 1][1] + 1;           } else {             a[i][j][1] = 0;           }         }       }       if (i == n - 1) {         for (int j = 0; j < m; ++j) {           dp1[i][j] = 0;         }       } else {         for (int j = 0; j < m; ++j) {           if (s[i][j] == s[i + 1][j])             dp1[i][j] = min(dp1[i + 1][j] + 1, min(a[i][j][0], a[i][j][1]));           else             dp1[i][j] = 0;         }       }     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         dp[i][j] = min(dp[i][j], dp1[i][j]);         ans += dp[i][j] + 1;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int i, l = s.length();     char max = s[0];     for (i = 1; i < l; i++) {       if (s[i] > max) max = s[i];     }     for (i = 0; i < l; i++) {       if (max == s[i]) cout << max;     }   }
#include <bits/stdc++.h>   using namespace std;   int used[200001];   int socks[200001];   bool used2[200001];   map<pair<int, int>, int> colors;   map<pair<int, int>, int>::iterator it;   int Stage = 0;   vector<vector<int> > V;   pair<int, int> P;   int MaXS = 0;   int countOfSocks = 0;   void Dfs(int v) {     countOfSocks++;     P.first = Stage;     P.second = socks[v];     colors[P]++;     MaXS = max(MaXS, colors[make_pair(Stage, socks[v])]);     for (int i = 0; i < V[v].size(); i++) {       if (used[V[v][i]] != true) {         used[V[v][i]] = true;         Dfs(V[v][i]);       }     }   }   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> socks[i];       vector<int> a;       V.push_back(a);     }     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       V[l].push_back(r);       V[r].push_back(l);       used2[l] = true;       used2[r] = true;     }     long long ans = 0;     if (m == 0) {       cout << 0;       return 0;     }     for (int i = 0; i < n; i++) {       if (used[i] == false && used2[i] == true) {         MaXS = 0;         countOfSocks = 0;         used[i] = true;         Dfs(i);         ans += countOfSocks - MaXS;         Stage++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct {     int i;     int j;   } AXIS;   AXIS D[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   bool DFS(char maze[][505], AXIS S, int &k, int &n, int &m) {     maze[S.i][S.j] =  * ;     for (int i = 0; i < 4; i++) {       AXIS next;       next.i = S.i + D[i].i;       next.j = S.j + D[i].j;       if (maze[next.i][next.j] ==  .  && 0 <= next.i && next.i < n &&           0 <= next.j && next.j < m && DFS(maze, next, k, n, m)) {         maze[next.i][next.j] =  X ;         k--;       }       if (!k) return 0;     }     return 1;   }   int main() {     int n, m, k;     char maze[505][505];     AXIS start = {-1, -1};     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> maze[i][j];         if (start.i < 0 && maze[i][j] ==  . ) {           start.i = i;           start.j = j;         }       }     }     DFS(maze, start, k, n, m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (maze[i][j] ==  * ) {           cout <<  . ;         } else {           cout << maze[i][j];         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   vector<int> ans[N];   int a[N], b[N], c[N];   int n, k, p;   int main() {     scanf( %d%d%d , &n, &k, &p);     int s = 0;     int _x = 0, _y = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       s += a[i];       if (a[i] & 1)         b[_x++] = a[i];       else         c[_y++] = a[i];     }     if ((k - p) & 1) {       if (s % 2 == 0) {         printf( NO n );         return 0;       }     }     if ((k - p) % 2 == 0) {       if (s & 1) {         printf( NO n );         return 0;       }     }     int j = 0;     if (_y >= p) {       for (int i = 0; i < p; ++i) {         ans[j++].push_back(c[i]);       }       if (_x < (k - p)) {         printf( NO n );         return 0;       } else {         for (int i = 0; i < k - p; ++i) {           ans[j++].push_back(b[i]);         }         for (int i = p; i < _y; ++i) ans[j - 1].push_back(c[i]);         for (int i = k - p; i < _x; ++i) ans[j - 1].push_back(b[i]);       }     } else {       for (int i = 0; i < _y; ++i) {         ans[j++].push_back(c[i]);       }       if (_x / 2 < (p - _y)) {         printf( NO n );         return 0;       }       for (int i = 0; i < p - _y; ++i) {         ans[j].push_back(b[i * 2]);         ans[j++].push_back(b[i << 1 | 1]);       }       if ((_x - (p - _y) * 2) < (k - p)) {         printf( NO n );         return 0;       } else {         for (int i = 2 * (p - _y); i < (2 * (p - _y) + k - p); ++i) {           ans[j++].push_back(b[i]);         }         for (int i = (2 * (p - _y) + k - p); i < _x; ++i)           ans[j - 1].push_back(b[i]);       }     }     printf( YES n );     for (int i = 0; i < j; ++i) {       int n = ans[i].size();       printf( %d  , n);       for (int k = 0; k < n; ++k) {         printf( %d  , ans[i][k]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, sum, mbit;   int Ask(vector<int> vec) {     int ret = 0;     printf( ? %d  , vec.size());     for (int i = 0; i < vec.size(); i++) printf( %d  , vec[i]);     puts(  );     fflush(stdout);     scanf( %d , &ret);     return ret;   }   int Solve(vector<int> a) {     vector<int> tmp;     int l = 0, r = a.size() - 1, ans = 0;     sort(a.begin(), a.end());     while (l <= r) {       int mid = (l + r) >> 1;       for (int i = 0; i <= mid; i++) tmp.push_back(a[i]);       int ret = Ask(tmp);       tmp.clear();       if (ret == y || ret == (y ^ x))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return a[ans];   }   int main() {     vector<int> vec;     scanf( %d%d%d , &n, &x, &y);     for (int i = 0; i <= 9; i++) {       for (int j = 1; j <= n; j++)         if (j >> i & 1) vec.push_back(j);       if (!vec.size()) break;       int ret = Ask(vec);       vec.clear();       if (ret == y || ret == (y ^ x)) sum |= (1 << i), mbit = i;     }     vector<int> ta, tb;     for (int i = 1; i <= n; i++)       if (i >> mbit & 1)         ta.push_back(i);       else         tb.push_back(i);     if (ta.size() > tb.size()) swap(ta, tb);     int pos1 = Solve(ta), pos2 = (sum ^ pos1);     if (pos1 > pos2) swap(pos1, pos2);     printf( ! %d %d n , pos1, pos2);     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, s1;   int a[1000];   set<string> l;   void fun() {     memset(a, 0, sizeof(a));     int len = s.length();     int j = 0;     for (int i = len - 1; i >= 0; i--) {       a[j++] = s[i] -  0 ;     }     a[0]++;     for (int i = 0; i < len; i++) {       if (a[i] >= 10) {         a[i + 1] += a[i] / 10;         a[i] %= 10;       }     }     if (a[len] != 0) len++;     int index;     for (int i = 0; i < len; i++) {       if (a[i] == 0) continue;       index = i;       break;     }     for (int i = len - 1; i >= index; i--) {       s1 += a[i] +  0 ;     }   }   int main() {     while (cin >> s) {       l.clear();       l.insert(s);       s1 =   ;       fun();       int sum = 1;       while (l.count(s1) != 1) {         l.insert(s1);         s = s1;         s1 =   ;         fun();         sum++;       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = long unsigned long;   using ld = double long;   template <class T, int N, int B>   struct asym_ra {     T a[N + 1];     T b[N / B + 2];     T get(int r) {       if (r <= 0) return T();       if (r > N) r = N;       return a[r] + b[r / B];     }     T operator()(int l, int r) { return get(r) - get(l); }     void add(int p, const T& v) {       for (int i = p + 1; i % B && i <= N; i++) a[i] += v;       for (int i = p / B + 1; i < N / B + 2; i++) b[i] += v;     }   };   int n;   int a[200005];   const int H = 300000;   asym_ra<ll, H + 5, 512> cnt;   asym_ra<ll, H + 5, 512> sum;   int main() {     ios::sync_with_stdio(!cin.tie(0));     cin >> n;     ll sol = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       for (int j = 0; j <= H; j += x) {         sol += sum(j, j + x) - cnt(j, j + x) * 1ll * j;       }       for (int q = 1;;) {         int r = x / q;         int l = x / (q + 1) + 1;         r++;         sol += x * cnt(l, r) - q * sum(l, r);         if (l == 1) break;         q = x / (l - 1);       }       sol += x * 1ll * cnt(x + 1, H + 1);       cout << sol <<    ;       cnt.add(x, 1);       sum.add(x, x);     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, cnt = 0;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++)       if (s[i] ==  2 ) cnt++;     if (cnt == 0) {       cout <<  YES  <<   n ;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (i == j)             cout <<  X ;           else             cout <<  = ;         }         cout <<   n ;       }     } else if (cnt == 1 || cnt == 2)       cout <<  NO  <<   n ;     else {       char a[n][n];       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) a[i][j] =  0 ;       }       cout <<  YES  <<   n ;       for (int i = 0; i < n; i++) {         bool win = 1;         for (int j = 0; j < n; j++) {           if (i == j)             a[i][j] =  X ;           else {             if (s[j] ==  1 )               a[i][j] =  = , a[j][i] =  = ;             else {               if (a[i][j] ==  0  and a[j][i] ==  0 ) {                 if (win)                   a[i][j] =  + , a[j][i] =  - , win = 0;                 else                   a[i][j] =  - , a[j][i] =  + ;               }             }           }         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) cout << a[i][j];         cout <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     while (n--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     T = 1;     while (T--) {       int n;       cin >> n;       vector<int> v;       int c = 0;       for (int i = 0; i < n; i++) {         int in;         cin >> in;         if (in == 5) {           c++;         }         v.push_back(in);       }       int nn = c / 9;       if (c == n) {         cout <<  -1  << endl;       } else {         string s =   ;         if (nn == 0) {           cout <<  0  << endl;         } else {           for (int i = 0; i < nn * 9; i++) {             s = s +  5 ;           }           for (int i = 0; i < n - c; i++) {             s = s +  0 ;           }           cout << s << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, c = 0;     char a;     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a;         if (a ==  C  || a ==  M  || a ==  Y ) c++;       }     }     if (c == 0)       cout <<  #Black&White  << endl;     else       cout <<  #Color  << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   int even[1 << 17];   bool used[1 << 17];   vector<int> path;   void addV(int v) {     path.push_back(v + 1);     even[v] ^= 1;   }   void dfs(int v, int p) {     used[v] = true;     addV(v);     for (int i(0); i <= ((long long)(((int)g[v].size())) - 1); ++i) {       int to(g[v][i]);       if (to == p) continue;       if (!used[to]) {         dfs(to, v);         addV(v);       }     }     if (even[v]) {       if (p == v) {         path.pop_back();       } else {         addV(p);         addV(v);       }     }   }   void solve() {     int n, m;     scanf( %d%d , &n, &m);     g.resize(n);     for (int i(0); i <= ((long long)(m)-1); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       g[a].push_back(b);       g[b].push_back(a);     }     for (int i(0); i <= ((long long)(n)-1); ++i) scanf( %d , &even[i]);     bool ok(false);     for (int i(0); i <= ((long long)(n)-1); ++i) {       if (!used[i]) {         if (even[i] && ok) {           puts( -1 );           return;         }         if (even[i]) {           dfs(i, i);           ok = true;         }       }     }     printf( %d n , ((int)path.size()));     for (int i(0); i <= ((long long)(((int)path.size())) - 1); ++i)       printf( %d%c , path[i], i + 1 == ((int)path.size()) ?   n  :    );   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10;   const int mod7 = 1e9 + 7;   const int mod = 1e9 + 7;   void read(int &a) {     a = 0;     int d = 1;     char ch;     while (ch = getchar(), ch >  9  || ch <  0 )       if (ch ==  - ) d = -1;     a = ch ^ 48;     while (ch = getchar(), ch >=  0  && ch <=  9 )       a = (a << 3) + (a << 1) + (ch ^ 48);     a *= d;   }   int b[N][35], p[N][35];   void ins(int x, int v) {     for (register int i = 0; i <= 30; i++) {       p[x][i] = p[x - 1][i];       b[x][i] = b[x - 1][i];     }     int now = x;     for (register int i = 30; i >= 0; i--) {       if (v & (1 << i)) {         if (!b[x][i]) {           b[x][i] = v;           p[x][i] = now;           return;         }         if (p[x][i] < now) {           swap(b[x][i], v);           swap(p[x][i], now);         }         v ^= b[x][i];       }     }   }   int query(int l, int r) {     int ans = 0;     for (register int i = 30; i >= 0; i--)       if (p[r][i] >= l && (b[r][i] ^ ans) > ans) ans ^= b[r][i];     return ans;   }   int main() {     int n;     read(n);     for (register int i = 1, x; i <= n; i++) {       read(x);       ins(i, x);     }     int T;     read(T);     while (T--) {       int l, r;       read(l), read(r);       printf( %d n , query(l, r));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, x, y;   int ABS(int x) { return (x < 0) ? (-x) : (x); }   int main() {     scanf( %d%d%d%d , &m, &x, &n, &y);     if (m > n) {       swap(m, n);       swap(x, y);     }     int d = ABS(x - y);     long long ans = 1 + m + n;     for (int i = 1; i <= m; i++) {       int b = i + d - 1, a = ABS(d - i) + 1;       a = max(a, 1);       b = min(b, n);       if (a <= b) ans += (b - a + 1) * 2 - 1;       if (i > d) ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, w;     cin >> n >> m >> w;     vector<long long> A(n);     for (int x = 0; x < n; x++) cin >> A[x];     long long low = 1, high = (long long)1e9 + m;     long long ans = low, mid;     while (high >= low) {       mid = (low + high) / 2;       long long left = 0;       vector<long long> tmp(n + 1);       long long add = 0;       vector<long long> B = A;       for (int x = 0; x < n; x++) {         add += tmp[x];         B[x] += add;         if (B[x] < mid) {           long long needed = mid - B[x];           tmp[min(n, w + x)] -= needed;           add += needed;           left += needed;         }       }       if (left <= m)         ans = max(mid, ans), low = mid + 1;       else         high = mid - 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int nextInt() {     int x;     scanf( %d , &x);     return x;   }   const int MAX_N = 1e5 + 100;   int arr[MAX_N];   int main() {     int n = nextInt();     for (int i = 0; i < n; ++i) arr[i] = nextInt();     sort(arr, arr + n);     for (int i = 1; i < n; ++i) {       if (arr[i] % arr[0] != 0) {         cout << -1 << endl;         return 0;       }     }     cout << arr[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, bool> ma;     char ch[100][100];     int n, m, answer = 0;     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; cin >> ch[i][j++])         ;     for (int i = 0; i < m; ++i) {       char Max = NULL;       for (int j = 0; j < n; Max = max(Max, ch[j++][i]))         ;       for (int j = 0; j < n; ++j)         if (ch[j][i] == Max && !ma[j]) {           ++answer;           ma[j] = true;         }     }     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 200010;   int a[maxN];   long long presum[maxN];   int n;   set<long long> st;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       presum[i] = presum[i - 1] + a[i];     }     for (int i = 1; i <= n; i++) {       long long M = 1;       while (M <= a[i]) M += M;       for (int j = i + 2; j <= n && presum[j - 1] - presum[i] <= M; j++)         if ((a[i] ^ a[j]) == (presum[j - 1] - presum[i]))           st.insert(1LL * i * n + j);       for (int j = i - 2; j >= 1 && presum[i - 1] - presum[j] <= M; j--)         if ((a[j] ^ a[i]) == (presum[i - 1] - presum[j]))           st.insert(1LL * j * n + i);     }     printf( %d n , (int)st.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = n;     sum += n / 2;     cout << sum << endl;     for (int i = 2; i <= n; i += 2) {       cout << i <<    ;     }     for (int i = 1; i <= n; i += 2) {       cout << i <<    ;     }     for (int i = 2; i <= n; i += 2) {       cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f ^= 1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return f ? x : -x;   }   int tar;   int val[26];   int tp[26];   int ans;   char cmd[26][105];   void dfs(int i) {     if (val[i - 1] == tar) {       printf( %d n , i - 1);       for (int j = 0; j < (int)(i - 1); ++j) puts(cmd[j + 1]);       exit(0);     }     if (i - 1 >= ans) return;     for (int j = 0; j < (int)(i); ++j)       for (int coef = 0; coef < (int)(4); ++coef) {         int mul = 1 << coef;         tp[i] = j * 10 + mul;         val[i] = mul * val[j];         sprintf(cmd[i],  lea e%cx, [%d*e%cx] , i +  a , mul, j +  a );         if (val[i] <= tar) dfs(i + 1);       }     for (int j = 0; j < (int)(i); ++j)       for (int k = 0; k < (int)(i); ++k)         for (int coef = 0; coef < (int)(4); ++coef) {           int mul = 1 << coef;           tp[i] = (j * 26 + k) * 10 + mul;           val[i] = val[j] + mul * val[k];           sprintf(cmd[i],  lea e%cx, [e%cx + %d*e%cx] , i +  a , j +  a , mul,                   k +  a );           if (val[i] <= tar) dfs(i + 1);         }   }   int main() {     tar = read();     val[0] = 1;     for (ans = 0; ans <= 26; ++ans) dfs(1);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, l, k, a[100005], x = 1;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n; i++) {       if (a[i] == 25) {         l++;       } else if (a[i] == 50) {         if (l < 1) {           x = 0;           break;         } else {           l--;           k++;         }       } else {         if (l > 0 && k > 0) {           l--;           k--;         } else if (l >= 3) {           l -= 3;         } else {           x = 0;           break;         }       }     }     if (x == 1)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   bool f;   int col[N];   long long p1 = 0, p2 = 0;   const long long mod = 998244353;   vector<int> E[N];   void dfs(int u) {     if (col[u] == 1)       p1++;     else       p2++;     for (int i = 0; i < E[u].size(); i++) {       int v = E[u][i];       if (!col[v]) {         if (col[u] == 1)           col[v] = 2;         else if (col[u] == 2)           col[v] = 1;         dfs(v);       } else if (col[u] == col[v])         f = 0;     }   }   long long fast_mod(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       b >>= 1;       a = (a * a) % mod;     }     return res;   }   int main() {     int t, n, m;     cin >> t;     while (t--) {       f = 1;       long long ans = 1;       cin >> n >> m;       for (int i = 1; i <= m; i++) {         int u, v;         cin >> u >> v;         E[u].push_back(v);         E[v].push_back(u);       }       for (int i = 1; i <= n; i++) {         if (!col[i]) {           col[i] = 1;           p1 = 0;           p2 = 0;           dfs(i);           ans = ans * ((fast_mod(2, p1) + fast_mod(2, p2)) % mod) % mod;         }       }       if (!f)         cout << 0 << endl;       else         cout << ans << endl;       for (int i = 1; i <= n; i++) E[i].clear(), col[i] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[52][15][4][15][4][15][4];   map<int, int> mp;   int check(char *a, char *b, int n) {     if (n == 0) return 1;     if (n > 1) {       if (dp[n][mp[a[n]]][mp[b[n]]][mp[a[n - 1]]][mp[b[n - 1]]][mp[a[n - 2]]]             [mp[b[n - 2]]])         return dp[n][mp[a[n]]][mp[b[n]]][mp[a[n - 1]]][mp[b[n - 1]]][mp[a[n - 2]]]                  [mp[b[n - 2]]];     }     int x;     char y;     int f = -1;     if (a[n] == a[n - 1] || b[n] == b[n - 1]) {       x = a[n - 1];       y = b[n - 1];       a[n - 1] = a[n];       b[n - 1] = b[n];       if (check(a, b, n - 1) == 1) f = 1;       a[n - 1] = x;       b[n - 1] = y;       dp[n][mp[a[n]]][mp[b[n]]][mp[a[n - 1]]][mp[b[n - 1]]][mp[a[n - 2]]]         [mp[b[n - 2]]] = f;       if (f == 1) return f;     }     if ((a[n] == a[n - 3] || b[n] == b[n - 3])) {       x = a[n - 3];       y = b[n - 3];       a[n - 3] = a[n];       b[n - 3] = b[n];       if (check(a, b, n - 1) == 1) return 1;       a[n - 3] = x;       b[n - 3] = y;       dp[n][mp[a[n]]][mp[b[n]]][mp[a[n - 1]]][mp[b[n - 1]]][mp[a[n - 2]]]         [mp[b[n - 2]]] = f;     }     return f;   }   int main() {     for (int i = 1; i <= 9; i++) mp[i +  0 ] = i;     mp[ T ] = 10;     mp[ J ] = 11;     mp[ Q ] = 12;     mp[ K ] = 13;     mp[ A ] = 0;     mp[ S ] = 0;     mp[ D ] = 1;     mp[ H ] = 2;     mp[ C ] = 3;     int n;     cin >> n;     char a[n];     char b[n];     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     if (check(a, b, n - 1) == 1)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }