malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int pri[26] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,                        43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, -1};   const long long mo[5] = {223092870ll, 2756205443ll, 907383479ll, 42600829ll,                            97ll};   long long a[10000], c, ans;   vector<long long> f[17][5];   int b[100], n, m, t, d, k, l;   char s[40];   void prework() {     int j = 0;     for (int i = 2; i <= 16; i++) {       for (j = 0, k = l = 1; k <= n; k *= i, l *= i + 1)         ;       for (j = 0; j < 5; j++) f[i][j].resize(l, -1);     }   }   int calc(int d, int p) {     int x = 0, y = 0;     for (int i = 0; i < t; i++) x = x * (d + 1) + b[i];     if (f[d][p][x] != -1) return x;     f[d][p][x] = 1;     for (int i = 0; i < t; i++)       if (b[i] == d) {         for (int j = 0; j < d; j++) {           b[i] = j;           f[d][p][x] = f[d][p][x] * f[d][p][calc(d, p)] % mo[p];         }         b[i] = d;         return x;       }     for (int i = 0; i < t; i++) y = y * d + b[i];     if (y < n) f[d][p][x] = a[y] % mo[p];     return x;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &a[i]);     prework();     scanf( %d , &m);     int flag;     while (m--) {       scanf( %d , &d);       scanf( %s , s);       scanf( %I64d , &c);       t = 0;       for (int j = 1; j <= n; t++, j *= d)         ;       for (int j = 0; j < t; j++) {         k = strlen(s) - t + j;         b[j] =             k >= 0                 ? (s[k] ==  ?  ? d : (s[k] <=  9  ? s[k] -  0  : s[k] + 10 -  A ))                 : 0;       }       flag = 25;       for (int i = 0; i < 5; i++) {         int key = calc(d, i);         ans = (f[d][i][key] + c) % mo[i];         for (int j = 0; j < 25; j++)           if ((mo[i] % pri[j] == 0) && (ans % pri[j] == 0)) {             flag = j;             break;           }         if (flag < 25) break;       }       printf( %d n , pri[flag]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[1000] = {4, 1, 1, 1, 2, 2, 2, 3, 3, 3};   int y[1000] = {2, 1, 2, 3, 1, 2, 3, 1, 2, 3};   int X[1005], Y[1005];   int main(int argc, char** argv) {     int n;     string a;     cin >> n >> a;     int mnx = 1e9, mny = 1e9, mxx = 0, mxy = 0;     for (int i = 1; i < a.size(); i++) {       X[i] = x[a[i] -  0 ] - x[a[i - 1] -  0 ];       Y[i] = y[a[i] -  0 ] - y[a[i - 1] -  0 ];     }     int cnt = 0;     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= 3; j++) {         if (i == 4 && j != 2) continue;         ++cnt;         int nowx = i, nowy = j;         for (int k = 1; k < a.size(); k++) {           nowx += X[k], nowy += Y[k];           if (nowx <= 3 && nowy <= 3 && nowx >= 1 && nowy >= 1 ||               (nowx == 4 && nowy == 2)) {           } else {             --cnt;             break;           }         }       }     }     if (cnt > 1)       puts( NO );     else       puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   std::ostream& operator<<(std::ostream& os, pair<int, int> p) {     os << p.first <<  ,   << p.second;     return os;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long int l, r;       cin >> l >> r;       if (l * 2 > r) {         cout << -1 <<     << -1 <<   n ;         continue;       } else {         cout << l <<     << 2 * l <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < n; i++) {       int up = 0, le = 0;       for (int j = i; j < n; j++) {         if (s[j] ==  U ) up++;         if (s[j] ==  D ) up--;         if (s[j] ==  L ) le++;         if (s[j] ==  R ) le--;         if (up == 0 && le == 0) cnt++;       }     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, i, j;   int main() {     cin >> n >> k;     if (2 * k >= n) {       cout << -1;       return 0;     }     cout << n * k << endl;     for (i = 1; i <= n; i++)       for (j = 0; j < k; j++) cout << i <<     << (i + j) % n + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long int bt[50 + 10];   map<int, int> MAP;   int main() {     long long int a, b, c, d, e, f, m, n, p, q, x, y, z, w, k;     vector<long long int> v[2525], temp;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> x;       bt[i] = x;       temp.push_back(x);     }     sort(temp.begin(), temp.end(), greater<long long int>());     for (int i = 0; i < temp.size(); i++) {       v[i + 1].push_back(temp[i]);     }     if (n >= k) {       for (int i = 1; i <= k; i++) {         cout << 1 <<     << bt[i] << endl;       }     } else {       long long int start = 2;       long long int end = n;       long long int mul = 1;       long long int cnt = 1;       int p = 0;       long long int get = n + 1;       while (get - 1 < k) {         for (int i = start; i <= end; i++) {           v[get] = v[i];           v[get].insert(v[get].end(), v[mul].begin(), v[mul].end());           get++;         }         start = end + 2;         end = get - 1;         mul++;       }       for (int i = 1; i <= k; i++) {         cout << v[i].size() <<    ;         long long int lmt = v[i].size();         cout << v[i][0];         for (int j = 1; j < lmt; j++) {           cout <<     << v[i][j];         }         cout << endl;       }     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ts = 1, cs = 1;     cin >> ts;     while (ts--) {       int n, m;       cin >> n >> m;       pair<int, int> vec[m + 2];       for (int i = 1; i <= m; i++) {         cin >> vec[i].first;         vec[i].second = i;       }       sort(vec + 1, vec + m + 1);       long long ans = 0;       for (int i = 1; i <= m; i++) {         for (int j = 1; j <= m; j++) {           if (vec[i].second > vec[j].second && vec[i].first > vec[j].first) ans++;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num, i, count = 0, sum = 0, a;     cin >> num;     a = 1;     while (1) {       for (i = 1; i <= a; i++) {         sum += i;       }       a++;       if (sum > num) break;       count++;     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 139;   const long long M = 1000012309;   long long p[200007];   vector<pair<long long, char> > vp1;   vector<pair<long long, char> > vp2;   long long hashtable[200007], hv, cnt = 0;   void pcal() {     p[0] = 1;     for (long long i = 1; i < 200007; ++i) p[i] = (p[i - 1] * base) % M;   }   void hashfunc() {     hashtable[0] = (vp1[0].first * vp1[0].second) % M;     ;     long long sz1 = vp1.size();     long long sz2 = vp2.size() - 2;     long long sz3 = vp2.size();     for (long long i = 1; i < sz1; ++i) {       long long val = (vp1[i].first * vp1[i].second) % M;       hashtable[i] = ((hashtable[i - 1] * base) % M + val) % M;     }     for (long long i = 0; i < sz1 - 1; ++i) {       long long l = i + 1;       long long r = i + sz2;       if (vp1[i].second == vp2[0].second && vp1[i].first >= vp2[0].first &&           r < sz1 - 1) {         long long bad = (hashtable[l - 1] * p[r - l + 1]) % M;         long long check = (hashtable[r] - bad + M) % M;         if (check == hv && vp1[r + 1].second == vp2[sz3 - 1].second &&             vp1[r + 1].first >= vp2[sz3 - 1].first)           cnt++;       }     }   }   int main() {     long long n, m;     cin >> n >> m;     long long d;     char c, a;     pcal();     for (long long i = 0; i < n; ++i) {       cin >> d >> c >> a;       if (i == 0)         vp1.push_back({d, a});       else {         long long sz = vp1.size();         if (a == vp1[sz - 1].second)           vp1[sz - 1].first += d;         else           vp1.push_back({d, a});       }     }     for (long long i = 0; i < m; ++i) {       cin >> d >> c >> a;       if (i == 0)         vp2.push_back({d, a});       else {         long long sz = vp2.size();         if (a == vp2[sz - 1].second)           vp2[sz - 1].first += d;         else           vp2.push_back({d, a});       }     }     if (vp1.size() < vp2.size()) {       cout << 0 << endl;       return 0;     } else if (vp2.size() == 1) {       long long sz1 = vp1.size();       cnt = 0;       for (long long i = 0; i < sz1; ++i) {         if (vp2[0].second == vp1[i].second && vp2[0].first <= vp1[i].first)           cnt += vp1[i].first - vp2[0].first + 1;       }       cout << cnt << endl;     } else if (vp2.size() == 2) {       long long sz1 = vp1.size();       cnt = 0;       for (long long i = 0; i < sz1 - 1; ++i) {         if (vp2[0].second == vp1[i].second && vp2[1].second == vp1[i + 1].second)           if (vp2[0].first <= vp1[i].first && vp2[1].first <= vp1[i + 1].first)             cnt++;       }       cout << cnt << endl;     } else if (vp2.size() > 2) {       long long sz = vp2.size();       cnt = 0;       hv = (vp2[0].first * vp2[0].second) % M;       for (long long i = 1; i < sz - 1; ++i) {         long long d = vp2[i].first;         long long a = vp2[i].second;         long long val = (d * a) % M;         hv = ((hv * base) % M + val) % M;       }       long long bad = ((vp2[0].first * vp2[0].second) % M * p[sz - 2]) % M;       hv = (hv - bad + M) % M;       hashfunc();       cout << cnt << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, tmp;   vector<int> nPos;   vector<int> NegPos, ZeroPos;   int minNeg = -1000000001, minNegPos = -1;   int main() {     scanf( %d n , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &tmp);       nPos.push_back(tmp);     }     for (int i = 0; i < n; i++) {       if (nPos[i] == 0) {         ZeroPos.push_back(i);       } else if (nPos[i] < 0) {         if (nPos[i] > minNeg) {           minNeg = nPos[i];           minNegPos = i;         }         NegPos.push_back(i);       }     }     for (int i = 1; i < ZeroPos.size(); i++) {       printf( 1 %d %d n , ZeroPos[i] + 1, ZeroPos[0] + 1);     }     if (NegPos.size() % 2 == 0) {       if ((!ZeroPos.empty()) && ZeroPos.size() < n) {         printf( 2 %d n , ZeroPos[0] + 1);       }       for (int i = 0; i < n; i++) {         if (nPos[i] != 0) {           for (int j = i + 1; j < n; j++) {             if (nPos[j] != 0) {               printf( 1 %d %d n , j + 1, i + 1);             }           }           break;         }       }     } else {       if (!ZeroPos.empty()) {         printf( 1 %d %d n , ZeroPos[0] + 1, minNegPos + 1);       }       if (ZeroPos.size() + 1 < n) {         printf( 2 %d n , minNegPos + 1);       }       for (int i = 0; i < n; i++) {         if (i != minNegPos && nPos[i] != 0) {           for (int j = i + 1; j < n; j++) {             if (j != minNegPos && nPos[j] != 0) {               printf( 1 %d %d n , j + 1, i + 1);             }           }           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int m = 1000000 + 3;   int db[1010];   int twospows[1010];   long long mpow(int b, int e) {     if (e == 0) return 1;     if (e == 1) return b;     return (mpow(b, e / 2) % m) * (mpow(b, e - e / 2) % m) % m;   }   long long twopow(int e) {     if (twospows[e] != -1) return twospows[e];     return twospows[e] = mpow(2, e);   }   long long solve(int n) {     if (n == 0) return 1;     if (db[n] != -1) return db[n];     long long v = twopow(n - 1);     for (int i = n - 1; i != 0; --i) {       v += twopow(n - i - 1) * solve(i);       v %= m;     }     return db[n] = v % m;   }   int main() {     int n;     cin >> n;     fill(db, db + 1010, -1);     fill(twospows, twospows + 1010, -1);     cout << solve(n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, k;     cin >> n >> m;     if (n < m) {       cout << -1;       return 0;     }     k = n / 2;     if (n % 2) k++;     for (i = k;; i++) {       if (i % m == 0) break;     }     cout << i;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     x = 0;     char c;     while (!isdigit(c = getchar()))       ;     do {       x = x * 10 + c -  0 ;     } while (isdigit(c = getchar()));   }   template <typename T>   inline void write(T x) {     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   void Write(string s) {     for (int i = 0; i < s.length(); i++) {       putchar(s[i]);     }   }   void Sangnt(bool nt[], int n) {     int x = sqrt(n);     nt[0] = true, nt[1] = true;     for (int i = 2; i <= x; i++) {       if (nt[i] == false) {         for (int j = i * i; j <= n; j += i) {           nt[j] = true;         }       }     }   }   void Congdon(int a[], int n) {     for (int i = 1; i < n; i++) {       a[i] += a[i - 1];     }   }   unsigned long long POW(int a, int b) {     if (b == 0) return 1;     unsigned long long y = POW(a, b / 2);     if (b % 2 == 0)       return y * y;     else       return y * y * a;   }   long long UCLN(long long x, long long y) {     long long r, a, b;     a = max(x, y), b = min(x, y);     while (b) {       r = a % b;       a = b, b = r;     }     return a;   }   string add(string a, string b) {     string ans;     while (a.length() < b.length()) a =  0  + a;     while (b.length() < a.length()) b =  0  + b;     ans = a;     int n = ans.length();     int digit, Add = 0;     for (int i = n - 1; i >= 0; i--) {       digit = (a[i] -  0  + b[i] -  0  + Add) % 10;       Add = (a[i] -  0  + b[i] -  0  + Add) / 10;       ans[i] = digit +  0 ;     }     if (Add == 1) ans =  1  + ans;     while (ans[0] ==  0  and ans.length() > 1) ans.erase(0, 1);     return ans;   }   string Minu(string a, string b) {     string ans;     while (a.length() < b.length()) a =  0  + a;     while (b.length() < a.length()) b =  0  + b;     ans = a;     int n = ans.length();     int digit, Add = 0;     for (int i = n - 1; i >= 0; i--) {       digit = a[i] - b[i] - Add;       if (digit < 0) {         digit = digit + 10;         Add = 1;       } else         Add = 0;       ans[i] = digit +  0 ;     }     while (ans[0] ==  0  and ans.length() > 1) ans.erase(0, 1);     return ans;   }   double a, b, c, x, y;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> a >> b >> c;     if (a == 0) {       if (b == 0) {         if (c == 0) {           cout << -1;         } else {           cout << 0;         }       } else {         cout << 1 << endl;         printf( %.10f , -c / b);       }     } else {       double delta = b * b - 4 * a * c;       if (delta == 0) {         x = -b / 2 / a;         cout << 1 << endl;         printf( %.10f , x);       } else if (delta < 0) {         cout << 0;       } else {         cout << 2 << endl;         x = -(b + sqrt(delta)) / 2 / a;         y = -(b - sqrt(delta)) / 2 / a;         if (x > y) {           swap(x, y);         }         printf( %.10f n , x);         printf( %.10f , y);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 1e9 + 7;   vector<int> check(int n, vector<int> a, int x) {     multiset<int> as;     for (auto u : a) {       as.insert(u);     }     vector<int> res;     for (int i = 0; i < n; ++i) {       auto it1 = as.end();       it1--;       int y = x - *it1;       as.erase(it1);       auto it2 = as.find(y);       if (it2 == as.end()) {         return {};       }       res.push_back(x - y);       res.push_back(y);       x = max(y, x - y);       as.erase(it2);     }     return res;   }   const int N = 3505;   int n, m, k;   int arr[N];   int get(int p, int s) {     int ans = (1 << 30);     for (int j = p; j + s <= m - 1; j++) {       ans = min(ans, max(arr[j], arr[n - (m - 1 - j) - 1]));     }     return ans;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       k = min(k, m - 1);       int ans = 0;       for (int i = 0; i < n; i++) scanf( %d , &arr[i]);       for (int i = 0; i <= k; i++) ans = max(ans, get(i, k - i));       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     int a[n][n];     int dp[2][n][n];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int v = 0; v < 2; v++) dp[v][i][j] = -100000000;     dp[1][0][0] = a[0][0];     for (int k = 1; k <= n + n - 2; k++) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) dp[0][i][j] = dp[1][i][j];       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) dp[1][i][j] = -100000000;       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           if (i == j) {             if (i > 0 && j > 0)               dp[1][i][j] = max(dp[1][i][j], dp[0][i - 1][j - 1] + a[i][k - i]);             if (i < k && j < k)               dp[1][i][j] = max(dp[1][i][j], dp[0][i][j] + a[i][k - i]);             if (i > 0 && j < k)               dp[1][i][j] = max(dp[1][i][j], dp[0][i - 1][j] + a[i][k - i]);             if (i < k && j > 0)               dp[1][i][j] = max(dp[1][i][j], dp[0][i][j - 1] + a[i][k - i]);           } else {             if (i > 0 && j > 0)               dp[1][i][j] = max(dp[1][i][j],                                 dp[0][i - 1][j - 1] + a[i][k - i] + a[j][k - j]);             if (i < k && j < k)               dp[1][i][j] =                   max(dp[1][i][j], dp[0][i][j] + a[i][k - i] + a[j][k - j]);             if (i > 0 && j < k)               dp[1][i][j] =                   max(dp[1][i][j], dp[0][i - 1][j] + a[i][k - i] + a[j][k - j]);             if (i < k && j > 0)               dp[1][i][j] =                   max(dp[1][i][j], dp[0][i][j - 1] + a[i][k - i] + a[j][k - j]);           }     }     cout << dp[1][n - 1][n - 1] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int n, m, K, px[N], py[N];   bool check(int k) {     vector<int> cx, cy;     cx.push_back(1), cx.push_back(n), cx.push_back(n + 1), cy.push_back(1),         cy.push_back(m), cy.push_back(m + 1);     for (int i = 0; i < K; i++) {       cx.push_back(max(1, px[i] - k)), cx.push_back(min(n, px[i] + k + 1));       cy.push_back(max(1, py[i] - k)), cy.push_back(min(m, py[i] + k + 1));     }     sort(cx.begin(), cx.end()),         cx.resize(unique(cx.begin(), cx.end()) - cx.begin());     sort(cy.begin(), cy.end()),         cy.resize(unique(cy.begin(), cy.end()) - cy.begin());     vector<vector<int> > cs(cx.size(), vector<int>(cy.size()));     int mnx = 2e9, mxx = 0, mny = 2e9, mxy = 0;     for (int i = 0; i < K; i++) {       int lx = max(1, px[i] - k), rx = min(n, px[i] + k), ly = max(1, py[i] - k),           ry = min(py[i] + k, m);       for (int j = 0, l, r; j < cx.size() - 1; j++) {         l = cx[j], r = cx[j + 1] - 1;         if (l >= lx && r <= rx) {           l = lower_bound(cy.begin(), cy.end(), ly) - cy.begin();           r = upper_bound(cy.begin(), cy.end(), ry) - cy.begin();           cs[j][l]++, cs[j][r]--;         }       }     }     bool b = 0;     for (int i = 0; i < cs.size() - 1; i++)       for (int j = 0; j < cs[i].size() - 1; j++) {         if (j) cs[i][j] += cs[i][j - 1];         if (!cs[i][j]) {           b = 1;           mnx = min(mnx, cx[i]), mxx = max(mxx, cx[i + 1] - 1);           mny = min(mny, cy[j]), mxy = max(mxy, cy[j + 1] - 1);         }       }     return !b || ((mxx - mnx + 1 <= 2 * k + 1) && (mxy - mny + 1 <= 2 * k + 1));   }   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 0; i < K; i++) {       scanf( %d%d , &px[i], &py[i]);     }     int l = 0, r = max(n, m), ans = 1e9;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid)) {         ans = min(ans, mid);         r = mid - 1;       } else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   int n, k, t, a, b;   long long w, z, x[3008], y[3008];   int main() {     for (ios::sync_with_stdio(0), cin.tie(0), cin >> n >> k; n--; z = b = 0) {       for (cin >> t; t--;)         for (cin >> a, z += a, ++b, a = k + 1; a-- > b;              y[a] < (w = x[a - b] + z) ? y[a] = w : 0)           ;       for (a = k + 1; a--; x[a] = y[a])         ;     }     cout << x[k], exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long int n, sum = 0, pos = 0, ans1 = 0, ans2 = 0;     cin >> n;     vector<unsigned long long int> vect;     vect.resize(n);     for (unsigned long long int i = 0; i < n; i++) {       cin >> vect[i];       sum += vect[i];     }     if (sum % n == 0) {       pos = sum / n;       for (unsigned long long int i = 0; i < n; i++) {         if (vect[i] > pos) {           ans1 += vect[i] - pos;         }       }       cout << ans1 << endl;     } else {       pos = (sum / n) + 1;       for (unsigned long long int i = 0; i < n; i++) {         if (vect[i] > pos) {           ans1 += vect[i] - pos;         } else if (vect[i] < pos - 1) {           ans2 += pos - 1 - vect[i];         }       }       cout << max(ans1, ans2) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void karem() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     karem();     int n, s = 0, res = 0;     cin >> n;     vector<int> v(12);     for (int i = int(0); i < 12; i++) cin >> v[i];     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (int i = int(0); i < 12; i++) {       if (s >= n) break;       s += v[i];       res++;     }     if (s < n)       cout << -1;     else       cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, a, b, c = 0;     cin >> n >> x;     while (n--) {       cin >> a >> b;       if (x == a || x == b || x == 7 - a || x == 7 - b) c++;       x = 7 - x;     }     if (c > 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void rf() {}   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int k = 0;     string s;     cin >> s;     k = 0;     for (int i = 0; i < s.size(); i++) {       if (k && s[i] ==  B ) {         k--;       } else {         k++;       }     }     cout << k << endl;   }   int main() {     fast();     rf();     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m;   int t;   int a[N];   string s;   int main() {     cin >> t;     while (t--) {       cin >> s;       int c = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  B ) c++;       }       if (s.length() % 2 == 0 && c == s.length() / 2)         puts( yes );       else         puts( no );     }     return 0;   }