malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[300003];   vector<int> adje[300003];   int d[300003];   int pickd[300003];   bool vis[300003];   int n, m;   int x;   int dfs1(int u) {     int ans = 0;     if (d[u] == -1)       x = u;     else if (d[u] == 1)       ++ans;     vis[u] = true;     for (int v : adj[u]) {       if (!vis[v]) {         ans += dfs1(v);       }     }     return ans;   }   int dfs2(int u) {     int ans = 0;     if (d[u] == 1) ++ans;     vis[u] = true;     for (int i = 0; i < ((int)(adj[u].size())); ++i) {       int v = adj[u][i];       if (!vis[v]) {         int c = dfs2(v);         if (c % 2) pickd[adje[u][i]] = 1;         ans += c;       }     }     return ans;   }   bool solve() {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         x = -1;         int c = dfs1(i);         if (c % 2) {           if (x == -1)             return false;           else {             d[x] = 1;           }         }       }     }     memset(vis, 0, sizeof(vis));     memset(pickd, 0, sizeof(pickd));     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         dfs2(i);       }     }     int k = accumulate(pickd + 1, pickd + m + 1, 0);     cout << k <<   n ;     for (int i = 1; i <= m; ++i) {       if (pickd[i]) {         cout << i <<    n [(--k) == 0];       }     }     return true;   }   int main() {     ios ::sync_with_stdio(0);     while (cin >> n >> m) {       for (int i = 1; i <= n; ++i) {         cin >> d[i];       }       for (int i = 1; i <= m; ++i) {         int u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);         adje[u].push_back(i);         adje[v].push_back(i);       }       if (!solve()) cout <<  -1 n ;       for (int i = 1; i <= n; ++i) {         adj[i].clear();         adje[i].clear();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char ch = getchar();     x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();   }   int n, m, mx, now, a[5200];   signed main() {     read(n), read(m);     int tmp = 0;     for (int i = 3; i <= n; ++i) {       if (i & 1) ++tmp;       mx += tmp;     }     if (m > mx) return puts( -1 ), 0;     a[1] = 1, a[2] = 2;     int p = n + 1;     tmp = 0;     for (int i = 3; i <= n; ++i) {       if (i & 1) ++tmp;       if (now + tmp > m) {         p = i - 1;         break;       }       now += tmp, a[i] = i;     }     m -= now;     if (m)       a[p + 1] = p - m * 2 + 1 + p, p += 2;     else       ++p;     for (int i = p; i <= n; ++i) a[i] = 200000000 + i * n;     for (int i = 1; i <= n; ++i) printf( %d  , a[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 5e3 + 10;   vector<double> vd;   int flag = 0;   vector<int> check(double x, int sz) {     vector<int> v;     int cur = 0;     double tot = x;     while (v.size() < sz) {       int o = tot / 10;       cur += o;       v.push_back(cur);       tot -= o * 10;       if (v.size() == sz) break;       tot += x;     }     if (flag) vd.push_back(tot);     return v;   }   double solve(vector<int>& v1, int o = 0) {     double l = 10 + 1e-10;     double r = INF;     int cnt = 200;     while (cnt--) {       double mid = (l + r) / 2;       auto v2 = check(mid, v1.size());       for (int i = 0; i < v1.size(); i++) {         if (v1[i] < v2[i]) {           r = mid;           break;         }         if (v1[i] > v2[i]) {           l = mid;           break;         }       }       if (v1 != v2) continue;       if (o == 0)         l = mid;       else         r = mid;     }     return l;   }   int main() {     int n;     cin >> n;     vector<int> v(n);     for (auto& x : v) cin >> x;     double key1 = solve(v, 0);     double key2 = solve(v, 1);     flag = 1;     if (key1 > key2) swap(key1, key2);     int ans1 = check(key1, n + 1).back();     int ans2 = check(key2, n + 1).back();     if (abs(vd[0] - 10) <= 1e-8) ans1++;     if (ans1 == ans2)       puts( unique ), printf( %d n , ans1), exit(0);     else       puts( not unique );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p[11];   int main() {     string s;     cin >> s;     int n = s.size();     p[0] = 1;     for (int i = 1; i < n; i++) p[i] = p[i - 1] * 9ll;     long long ans = 1ll;     for (char c : s) ans *= (long long)(c -  0 );     ans = max(ans, p[n - 1]);     long long pre = 1;     for (int i = 1; i <= n; i++) {       for (long long j = 1; j < s[i - 1] -  0 ; j++) {         ans = max(ans, pre * j * p[n - i]);       }       pre *= (long long)(s[i - 1] -  0 );     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a;     cin >> a;     int sum = 0;     char b[3] = { R ,  G ,  B };     for (int i = 1; i < n; i++) {       if (a[i - 1] == a[i] && a[i] == a[i + 1]) {         for (int j = 0; j < 3; j++) {           if (b[j] != a[i]) {             a[i] = b[j];             break;           }         }         sum++;       } else if (a[i - 1] == a[i]) {         for (int j = 0; j < 3; j++) {           if (b[j] != a[i] && b[j] != a[i + 1]) {             a[i] = b[j];             break;           }         }         sum++;       }     }     printf( %d n , sum);     for (int i = 0; i < n; i++) {       printf( %c , a[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long r, i;     int flag = 1;     cin >> r;     for (i = 1; i <= 1000000; i++) {       if ((r - i * i - i - 1) > 0 && (r - i * i - i - 1) % (2 * i) == 0) {         flag = 0;         break;       }     }     if (flag == 0)       printf( %lld %lld n , i, (r - i * i - i - 1) / 2 * i);     else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int distance(int x1, int y1, int x2, int y2) {     return (int)ceil(sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, x, q, cnt = 0;     string t;     char ch;     map<char, vector<pair<int, int>>> keys;     int freq[26] = {0};     cin >> n >> m >> x;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch;         if (!freq[ch -  a ]) freq[ch -  a ]++;         keys[ch].push_back(make_pair(i, j));       }     }     if (keys.count( S )) {       vector<pair<int, int>> shiftCords = keys[ S ];       vector<pair<int, int>> chCords;       for (int i =  a ; i <=  z ; i++) {         if (keys.count(i)) {           chCords = keys[i];           bool validDistance = 0;           for (int j = 0; j < (int)chCords.size(); j++) {             for (int k = 0; k < (int)shiftCords.size(); k++) {               if (distance(chCords[j].first, chCords[j].second,                            shiftCords[k].first, shiftCords[k].second) <= x) {                 freq[i -  a ]++;                 validDistance = 1;                 break;               }             }             if (validDistance) break;           }         }       }     }     cin >> q;     cin >> t;     for (int i = 0; i < q; i++) {       char c = t[i];       if (islower(c)) {         if (!freq[c -  a ]) {           cout << -1 << endl;           return 0;         }       } else {         c = tolower(c);         if (!keys.count( S ) || !freq[c -  a ]) {           cout << -1 << endl;           return 0;         } else {           if (freq[c -  a ] == 1) cnt++;         }       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     int maxP = 0;     int maxQ = 0;     for (int i = 0; i < k; i++) {       int p = 0;       int q = 0;       cin >> p;       cin >> q;       if (p < q) {         cout <<  Happy Alex  << endl;         return 0;       }     }     cout <<  Poor Alex  << endl;     return 0;   }
#include <bits/stdc++.h>   const int maxn = 4e5 + 10;   const int maxm = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const double eps = 1e-7;   using namespace std;   long long cnt[25][25], dp[1 << 21];   int n;   vector<int> col[25];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       col[x].push_back(i);     }     for (int i = 1; i <= 20; ++i)       for (int j = 1; j <= 20; ++j)         if (i != j) {           if (!col[i].size() || !col[j].size()) continue;           int l = 0;           for (int k = 0; k < col[i].size(); ++k) {             while (true) {               if (l == col[j].size() - 1 || col[j][l + 1] > col[i][k]) break;               l++;             }             if (col[j][l] < col[i][k]) cnt[i][j] += l + 1;           }         }     memset(dp, 0x3f, sizeof dp);     dp[0] = 0;     for (int S = 0; S < 1 << 20; ++S) {       for (int i = 0; i < 20; ++i)         if (!(S >> i & 1)) {           long long sum(0);           for (int j = 0; j < 20; ++j)             if (S >> j & 1) sum += cnt[j + 1][i + 1];           dp[S | (1 << i)] = min(dp[S | (1 << i)], dp[S] + sum);         }     }     cout << dp[(1 << 20) - 1] << endl;     return ~~(0 - 0);   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long v;     cin >> v;     for (long long i = 0; i < v; i++) {       vector<long double> arr(250);       for (long long j = 0; j < 250; j++) cin >> arr[j];       long double avg1 = 0;       for (long long j = 0; j < 250; j++) avg1 += arr[j];       avg1 /= 250.0;       sort(arr.begin(), arr.end());       long double v1 = ((arr[249] - arr[0]) * (arr[249] - arr[0])) / 12.0;       long double v2 = 0;       for (long long j = 0; j < 250; j++)         v2 += ((avg1 - arr[j]) * (avg1 - arr[j]));       v2 /= 250.0;       long double avg2 = 0;       if (abs(v2 - avg1) > abs(v1 - v2))         cout <<  uniform n ;       else         cout <<  poisson n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(string new_l, string old_l) {     int len_1;     int col_izm;     col_izm = 0;     len_1 = new_l.length();     if (len_1 == old_l.length()) {       for (int i = 0; i < len_1; i++) {         if (new_l[i] == old_l[i]) {           col_izm++;         } else if (((new_l[i] ==  1 ) || (new_l[i] ==  i ) || (new_l[i] ==  l ) ||                     (new_l[i] ==  I ) || (new_l[i] ==  L )) &&                    ((old_l[i] ==  1 ) || (old_l[i] ==  i ) || (old_l[i] ==  l ) ||                     (old_l[i] ==  I ) || (old_l[i] ==  L ))) {           col_izm++;         } else if (((new_l[i] ==  0 ) || (new_l[i] ==  o ) ||                     (new_l[i] ==  O )) &&                    ((old_l[i] ==  0 ) || (old_l[i] ==  o ) ||                     (old_l[i] ==  O ))) {           col_izm++;         } else if (((new_l[i] - old_l[i]) == 32) ||                    ((new_l[i] - old_l[i]) == -32)) {           col_izm++;         } else           return true;       }       if (col_izm == len_1)         return false;       else         return true;     } else       return true;   }   int main() {     string n_login, login;     int col;     cin >> n_login;     cin >> col;     for (int i = 0; i < col; i++) {       cin >> login;       if (!check(n_login, login)) {         cout <<  No  << endl;         return 0;       }     }     cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); }   int maximum(int a, int b) {     if (a > b) {       return a;     } else {       return b;     }   }   int minimum(int a, int b) {     if (a < b) {       return a;     } else {       return b;     }   }   int main() {     int a[2000];     int p = 0, q = 1, x = 1, i, j;     int pl, pr, vl, vr, k;     long long c = 0, d;     a[0] = 0;     for (i = 0; i < 9; i++) {       for (j = p; j < q; j++) {         a[x++] = a[j] * 10 + 4;         a[x++] = a[j] * 10 + 7;       }       p = q;       q = x;     }     qsort(a, x, sizeof(int), cmp);     a[x] = 1000000001;     scanf( %d %d %d %d %d , &pl, &pr, &vl, &vr, &k);     d = (long long)(pr - pl + 1) * (vr - vl + 1);     for (i = 1; i <= x - k; i++) {       if (pl <= a[i] && vr >= a[i + k - 1]) {         int s1 = minimum(a[i], pr);         int s2 = maximum(a[i - 1] + 1, pl);         int t1 = maximum(a[i + k - 1], vl);         int t2 = minimum(a[i + k] - 1, vr);         if (s1 - s2 >= 0 && t2 - t1 >= 0) {           c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);         }       }       if (vl <= a[i] && pr >= a[i + k - 1]) {         int s1 = minimum(a[i], vr);         int s2 = maximum(a[i - 1] + 1, vl);         int t1 = maximum(a[i + k - 1], pl);         int t2 = minimum(a[i + k] - 1, pr);         if (s1 - s2 >= 0 && t2 - t1 >= 0) {           c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);         }       }     }     if (k == 1) {       for (i = 1; i < x; i++) {         if (pl <= a[i] && pr >= a[i] && vl <= a[i] && vr >= a[i]) c--;       }     }     printf( %.20lf n , (double)c / d);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5100;   char Map[N][N];   int dp[N][N];   int main() {     int i, j;     int line, row;     scanf( %d%d , &line, &row);     for (i = 0; i < line; i++) scanf( %s , Map[i]);     for (i = 0; i < line; i++) {       for (j = row - 1; j >= 0; j--) {         if (Map[i][j] ==  1 )           dp[j][i] = dp[j + 1][i] + 1;         else           dp[j][i] = 0;       }     }     int ret = 0;     for (i = 0; i < row; i++) {       sort(dp[i], dp[i] + line);       for (j = 0; j < line; j++) {         ret = max(ret, (line - j) * dp[i][j]);       }     }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long s[1000005];   int main(void) {     int n, d, ans = 0;     cin >> n >> d >> s[1];     for (int i = 2; i <= n; ++i) {       cin >> s[i];       int cnt = 0;       if (s[i] <= s[i - 1]) cnt = (s[i - 1] - s[i] + d) / d;       s[i] += cnt * d;       ans += cnt;     }     return cout << ans <<   n , 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx )   using namespace std;   const double eps = 0.000001;   const long double pi = acos(-1);   const int maxn = 1e7 + 9;   const int mod = 1e9 + 7;   const long long MOD = 1e18 + 9;   const long long INF = 1e18 + 123;   const int inf = 2e9 + 11;   const int mxn = 1e6 + 9;   const int N = 3e5 + 123;   const int PRI = 555557;   const int pri = 997;   int tests = 1;   int n, m, q;   int sz[N], pr[N], ans[N];   bool u[N];   vector<int> g[N];   void dfs(int v, int p = 1) {     sz[v] = 1;     pr[v] = p;     for (int to : g[v]) {       if (to == p) continue;       dfs(to, v);       sz[v] += sz[to];     }   }   void dfs_center(int v) {     u[v] = 1;     if (sz[v] == 1) {       ans[v] = v;       return;     }     int mx = g[v].back();     for (int to : g[v]) {       if (u[to]) continue;       dfs_center(to);       if (sz[mx] < sz[to]) {         mx = to;       }     }     int c = ans[mx];     while (sz[v] > sz[c] * 2) {       c = pr[c];     }     ans[v] = c;   }   inline void Solve() {     cin >> n >> q;     for (int i = 2; i <= n; i++) {       int x;       cin >> x;       g[x].push_back(i);     }     dfs(1);     dfs_center(1);     while (q--) {       int x;       cin >> x;       cout << ans[x] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     while (tests--) {       Solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, i, j;     char x[2], y[2], t;     cin >> n >> m;     cin >> x[0];     for (i = 2; i < n; i++) cin >> t;     cin >> x[1] >> y[0];     y[0] = (y[0] ==  ^ ) ?  >  :  < ;     for (j = 2; j < m; j++) cin >> t;     cin >> y[1];     y[1] = (y[1] ==  ^ ) ?  >  :  < ;     if (x[0] == y[0] && x[1] == y[1] && x[0] != x[1])       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = int(1e9) + 7;   int debug = 0;   const int N = int(2e3) + 5;   using namespace std;   int a[N], b[N], p[N];   int main() {     int i, j, n, t;     ios::sync_with_stdio(false);     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     int ans = 0;     vector<pair<int, int> > moves;     for (i = 0; i < n; i++) p[a[i]] = i;     for (i = 0; i < n; i++) {       int pos = -1;       for (j = 0; j < n; j++)         if (debug)           cerr <<  j                 <<  :   << j <<   |                  <<  b[j]                 <<  :   << b[j] << endl;       ;       for (j = 0; j < n; j++)         if (p[b[j]] == i) pos = j;       if (j == i) continue;       if (debug)         cerr <<  pos               <<  :   << pos <<   |                <<  i               <<  :   << i << endl;       ;       int cur = pos;       for (j = pos - 1; j >= i; j--) {         if (p[b[j]] >= cur) {           ans += cur - j;           moves.push_back(make_pair(j, cur));           b[cur] = b[j];           b[j] = i;           cur = j;         }       }     }     cout << ans <<   n ;     reverse(moves.begin(), moves.end());     cout << moves.size() <<   n ;     for (i = 0; i < moves.size(); i++)       cout << moves[i].second + 1 <<     << moves[i].first + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3079;   int r, c, n, k;   vector<int> nx(maxn, -1), pv(maxn, -1), kth(maxn, -1);   vector<vector<int> > my(maxn);   class point {    public:     int x, y;   };   bool cmp(point& a, point& b) { return (a.y == b.y ? a.x < b.x : a.y < b.y); }   vector<point> v(maxn);   long long sum(int i) { return (v[i].y - v[pv[i]].y) * (c + 1 - v[kth[i]].y); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> r >> c >> n >> k;     long long ans = 0;     int m = n + k + 1;     for (int i = 1; i <= n; i++) cin >> v[i].x >> v[i].y;     v[0] = {r + 1, 0};     for (int i = n + 1; i < m; i++) v[i] = {r + 1, c + 1};     sort(v.begin(), v.begin() + m, cmp);     for (int i = n + 1; i < m; i++)       kth[i] = m - 1, pv[i] = i - 1, nx[i] = min(m - 1, i + 1);     for (int i = m - 1; i >= 0; i--) my[v[i].x].push_back(i);     for (int x1 = 1; x1 <= r; x1++) {       int p = 0;       for (int i = 1; i <= n; i++) {         if (v[i].x < x1) continue;         nx[p] = i, pv[i] = p;         p = i;       }       nx[p] = n + 1, pv[n + 1] = p;       kth[p] = (k == 1 ? p : pv[m - 1]);       for (int i = p; i >= 0; i = pv[i]) kth[i] = pv[kth[nx[i]]];       long long cur = 0;       for (int i = nx[0]; i <= n; i = nx[i]) cur += sum(i);       for (int x2 = r; x2 >= x1; x2--) {         ans += cur;         for (int i : my[x2]) {           cur -= sum(i);           for (int j = pv[i], cnt = 0; cnt < k - 1 && j; cnt++, j = pv[j]) {             cur -= sum(j);             if (j < i) kth[j] = nx[kth[j]];             cur += sum(j);           }           cur -= sum(nx[i]);           nx[pv[i]] = nx[i], pv[nx[i]] = pv[i];           cur += sum(nx[i]);         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 233;   const int INF = numeric_limits<int>::max();   void read(int &x) {     x = 0;     char ch = getchar();     int f = 1;     while (!isdigit(ch)) (ch ==  -  ? f = -1 : 0), ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   int f[N][105], g[105];   int n, K, p, a[N], nw, s[N];   int x, sum, st[N], tp;   signed main() {     memset(g, 0x7f, sizeof(g));     memset(f, 0x7f, sizeof(f));     read(n);     read(K);     read(p);     if (p * K > n) {       for (int i = 1; i <= n; ++i) {         read(x);         x %= p;         a[i] = x;         sum = (sum + a[i]) % p;         f[i][1] = sum;         g[1] = sum;         for (int j = min(K, i); j >= 2; --j)           if (i == j) {             f[i][j] = f[i - 1][j - 1] + x;             g[j] = x;           } else {             int l = f[i - 1][j - 1] + x;             int r = f[i - 1][j] + x;             if (g[j] + x >= p) r -= p;             if (l < r)               f[i][j] = l, g[j] = x;             else if (l > r)               f[i][j] = r, g[j] = (g[j] + x) % p;             else               f[i][j] = l, g[j] = max(x, (g[j] + x) % p);           }       }       return printf( %d , f[n][K]), 0;     }     for (int i = 1; i <= n; ++i)       read(a[i]), a[i] %= p, sum += a[i], s[i] = (s[i - 1] + a[i]) % p;     for (int i = 1; i <= n - 1; ++i) {       int pos = upper_bound(st + 1, st + 1 + tp, s[i]) - st;       if (pos > tp) ++tp;       st[pos] = s[i];     }     int pos = upper_bound(st + 1, st + 1 + tp, s[n]) - st;     if (pos >= K)       printf( %d , s[n]);     else       printf( %d , s[n] + p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int y;   vector<pair<int, int> > p[3];   int dp[111][111][3];   bool check(int x, int t, int y) {     for (int i = 0; i < p[y].size(); i++) {       if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t) return false;     }     return true;   }   int go(int x, int t, int y) {     if (x == n - 1) return true;     int& res = dp[x][t][y];     if (res != -1) return res;     res = 0;     for (int i = 0; i < p[y].size(); i++) {       if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t ||           x + 1 >= p[y][i].first - 2 * t && x + 1 <= p[y][i].second - 2 * t)         return res = false;     }     if (check(x + 1, t, y)) res |= go(x + 1, t + 1, y);     if (check(x + 1, t, min(2, y + 1))) res |= go(x + 1, t + 1, min(2, y + 1));     if (check(x + 1, t, max(y - 1, 0))) res |= go(x + 1, t + 1, max(y - 1, 0));     return res;   }   void R(string s, int v) {     int i = 0;     if (s[0] ==  s ) {       y = v;       s[0] =  . ;     }     while (i < s.size()) {       if (s[i] !=  . ) {         int l = i;         int r = l;         while (i < s.size() && s[i] == s[l]) i++;         r = i - 1;         i--;         p[v].push_back(make_pair(l, r));         if (i == s.size() - 1) return;       }       i++;     }   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       p[0].clear();       p[1].clear();       p[2].clear();       memset(dp, -1, sizeof(dp));       cin >> n >> k;       string s1, s2, s3;       cin >> s1 >> s2 >> s3;       R(s1, 0);       R(s2, 1);       R(s3, 2);       if (go(0, 0, y))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }