malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bitset<2005> a[2005];   int n, m, i, j, deg[2005], t, ans[2005], z[2005];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &m);       for (i = 1; i <= n; i++) {         a[i].reset();         deg[i] = 0;       }       for (i = 1; i <= m; i++) {         int x, y;         scanf( %d%d , &x, &y);         deg[x]++;         deg[y]++;         a[x][n + 1] = a[x][n + 1] ^ 1;         a[y][n + 1] = a[y][n + 1] ^ 1;         a[x][y] = a[y][x] = 1;       }       bool f = 1;       for (i = 1; i <= n; i++) {         if (deg[i] & 1) {           f = 0;           a[i][i] = 1;         }       }       if (f) {         puts( 1 );         for (i = 1; i <= n; i++) {           printf( %d%c , 1, (i == n ?   n  :    ));         }         continue;       }       for (i = 1; i <= n; i++) {         int t = -1;         for (j = i; j <= n; j++) {           if (a[j][i]) {             t = j;             break;           }         }         if (t == -1) {           for (j = 1; j < i; j++) a[j][i] = 0;           ans[i] = 0;           z[i] = 1;           continue;         }         z[i] = 0;         swap(a[i], a[t]);         for (j = i + 1; j <= n; j++) {           if (a[j][i]) a[j] ^= a[i];         }       }       for (i = n; i >= 1; i--) {         if (z[i]) continue;         for (j = i + 1; j <= n; j++) {           if (a[i][j]) a[i][n + 1] = a[i][n + 1] ^ ans[j];         }         ans[i] = a[i][n + 1];       }       puts( 2 );       for (i = 1; i <= n; i++) {         printf( %d%c , 1 + ans[i], (i == n ?   n  :    ));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char inc(char &c) {     char ret = c;     if (c ==  z )       c =  a ;     else       ++c;     return ret;   }   int main() {     int n;     cin >> n;     char t[4][n];     char c =  a ;     t[0][0] = t[1][0] = inc(c);     for (int i = 1; i < n; ++i) {       if (i % 2 == 0) {         t[0][i] = t[0][i - 1] = inc(c);         t[1][i] = t[1][i - 1] = inc(c);       } else {         t[2][i] = t[2][i - 1] = inc(c);         t[3][i] = t[3][i - 1] = inc(c);       }     }     if (n % 2 == 0)       t[0][n - 1] = t[1][n - 1] = inc(c);     else       t[2][n - 1] = t[3][n - 1] = inc(c);     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < n; ++j) cout << t[i][j];       cout << endl;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 5e5 + 3;   const long long MOD = 998244353;   int board[4][52];   int n;   vector<pair<int, pair<int, int> > > moves;   bool flag;   void make_move(int a, int b, int x, int y) {     if (board[a][b] == 0 && board[x][y] == 0) return;     moves.push_back(         pair<int, pair<int, int> >(board[a][b], pair<int, int>(x, y)));     board[x][y] = board[a][b];     board[a][b] = 0;     flag = true;   }   void enter() {     for (int i = 0; i < n; i++) {       if (board[0][i] == board[1][i]) {         make_move(1, i, 0, i);       }       if (board[3][i] == board[2][i]) {         make_move(2, i, 3, i);       }     }   }   const int dx[] = {0, 1, 0, -1};   const int dy[] = {-1, 0, 1, 0};   void print() {     for (int i = 0; i < 4; i++) {       for (int j = 0; j < n; j++) {         printf( %2d  , board[i][j]);       }       puts(  );     }     puts(  );   }   void move() {     int f = -1, c = -1;     for (int i = 0; i < n; i++) {       if (board[1][i] == 0) {         f = 1;         c = i;         break;       }       if (board[2][i] == 0) {         f = 2;         c = i;         break;       }     }     if (f == -1) return;     int d;     if (f == 1)       d = 0;     else       d = 2;     for (int t = 0; t < 2 * n - 1; t++) {       int nf = f + dx[d];       int nc = c + dy[d];       if (nf >= 1 && nf <= 2 && nc >= 0 && nc < n) {         make_move(nf, nc, f, c);         f = nf;         c = nc;       } else {         t--;         d = (d + 1) % 4;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int k;     cin >> n >> k;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < n; j++) {         cin >> board[i][j];       }     }     flag = true;     while (flag) {       flag = false;       enter();       move();     }     if (moves.size()) {       cout << moves.size() <<   n ;       for (auto x : moves) {         cout << x.first <<     << x.second.first + 1 <<     << x.second.second + 1              <<   n ;       }     } else {       cout << -1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int N = 100005;   LL a[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       LL sum = 0;       LL x;       scanf( %d%lld , &n, &x);       LL q = n;       for (int i = 1; i <= n; ++i) {         scanf( %lld , &a[i]);         sum += a[i];       }       sort(a + 1, a + n + 1);       bool flag = true;       for (int i = 1; i <= n; ++i) {         if (sum * 1.0 / q * 1.0 >= x * 1.0) {           printf( %lld n , q);           flag = false;           break;         }         sum -= a[i], --q;       }       if (flag) printf( %lld n , q);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num_q;   int flag;   long long u, v, w;   map<long long, long long> hs;   int main() {     scanf( %d , &num_q);     while (num_q--) {       scanf( %d%lld%lld , &flag, &u, &v);       if (flag == 1) {         scanf( %lld , &w);         while (u != v) {           if (u > v) {             hs[u] += w;             u /= 2;           } else {             hs[v] += w;             v /= 2;           }         }       } else {         long long ans = 0;         while (u != v) {           if (u > v) {             ans += hs[u];             u /= 2;           } else {             ans += hs[v];             v /= 2;           }         }         printf( %lld n , ans);       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct EDGE {     int adj, next;   } edge[810000];   int n, m, q, top, gh[510000];   int size[510000], dfn[510000], low[510000], cnt, ind, stop, instack[510000],       stck[510000], belong[510000];   void addedge(int x, int y) {     edge[++top].adj = y;     edge[top].next = gh[x];     gh[x] = top;   }   void tarjan(int x, int pre) {     dfn[x] = low[x] = ++ind;     instack[x] = 1;     stck[++stop] = x;     for (int p = gh[x]; p; p = edge[p].next) {       if (edge[p].adj == pre) continue;       if (!dfn[edge[p].adj]) {         tarjan(edge[p].adj, x);         low[x] = min(low[x], low[edge[p].adj]);       } else if (instack[edge[p].adj]) {         low[x] = min(low[x], dfn[edge[p].adj]);       }     }     if (dfn[x] == low[x]) {       ++cnt;       int tmp = 0;       size[cnt] = 0;       while (tmp != x) {         size[cnt]++;         tmp = stck[stop--];         belong[tmp] = cnt;         instack[tmp] = 0;       }     }   }   int far[510000];   long long mul[510000];   void init() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) gh[i] = 0;     top = cnt = ind = stop = 0;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       addedge(x, y);       addedge(y, x);     }     for (int i = 1; i <= n; i++) dfn[i] = 0;     for (int i = 1; i <= n; i++)       if (dfn[i] == 0) tarjan(i, 0);   }   int v[510000];   void prepare() {     for (int i = 1; i <= n; i++) v[i] = 0;     int tail = 1;     v[belong[1]]++;     for (int i = 1; i <= n; i++) {       while (tail < n && (v[belong[tail + 1]] + 1 < size[belong[tail + 1]] ||                           size[belong[tail + 1]] == 1)) {         v[belong[++tail]]++;       }       far[i] = tail;       mul[i] = tail - i + 1;       mul[i] += mul[i - 1];       v[belong[i]]--;     }   }   int main() {     init();     prepare();     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       int left = l;       int right = r;       if (far[l] > r)         left = left - 1;       else         while (left < right) {           int mid = (left + right) / 2 + 1;           if (far[mid] <= r)             left = mid;           else             right = mid - 1;         }       long long ans = mul[left] - mul[l - 1];       ans += (long long)(r - left + 1) * (r - left) / 2;       printf( %I64d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int squ(vector<long long> &v) {     for (int i = 0; i + 3 < v.size(); i++) {       if (v[i] == v[i + 1] && v[i] == v[i + 2] && v[i] == v[i + 3]) return v[i];     }     return -1;   }   vector<long long> pa(vector<long long> &v) {     vector<long long> q;     for (int i = 0; i + 1 < v.size(); i++) {       if (i == 0 || v[i - 1] != v[i]) {         if (v[i] == v[i + 1]) q.push_back(v[i]);       }     }     return q;   }   bool checkv(pair<long long, long long> a, pair<long long, long long> b) {     if ((a.first + a.second) * (a.first + a.second) * b.first * b.second >         (b.first + b.second) * (b.first + b.second) * a.first * a.second)       return true;     return false;   }   int main() {     ios_base::sync_with_stdio(0);     int T;     cin >> T;     while (T--) {       long long n;       cin >> n;       vector<long long> v;       for (int i = 0; i < n; i++) {         long long a;         cin >> a;         v.push_back(a);       }       sort(v.begin(), v.end());       long long res = squ(v);       if (res > 0) {         for (int i = 0; i < 4; i++) cout << res <<    ;         cout <<   n ;         continue;       }       vector<long long> u = pa(v);       pair<long long, long long> cur = {u[0], u[1]};       for (int i = 0; i + 1 < u.size(); i++) {         if (checkv(cur, {u[i], u[i + 1]})) {           cur = {u[i], u[i + 1]};         }       }       cout << cur.first <<     << cur.first <<     << cur.second <<                << cur.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 100011;   const int inf = 1e9 + 7;   int n, m;   char c[1000][1000];   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = (1), _b = (n); i <= _b; ++i)       for (int j = (1), _b = (m); j <= _b; ++j) cin >> c[i][j];     long long res = 0, ok = 0;     for (int i = (1), _b = (m); i <= _b; ++i) {       if (c[n][i] ==  B ) {         if (!ok) res++;         ok = 1;       } else         ok = 0;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int x[N], y[N];   vector<int> xx;   vector<int> yy;   int n;   bool sameline(int tar, int p1, int p2) {     return 1LL * (y[tar] - yy[p1]) * (x[tar] - xx[p2]) ==            1LL * (y[tar] - yy[p2]) * (x[tar] - xx[p1]);   }   bool check(int p1, int p2, int p3, int p4) {     for (int i = 1; i <= n; i++) {       if (!sameline(i, p1, p2) && !sameline(i, p3, p4)) return false;     }     return true;   }   int main() {     int flag;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]);     if (n <= 4) {       printf( YES n );       return 0;     }     xx.push_back(x[1]);     yy.push_back(y[1]);     xx.push_back(x[2]);     yy.push_back(y[2]);     for (int i = 3; i <= n; i++) {       flag = 1;       for (int j = 0; j < xx.size() - 1; j++) {         for (int k = j + 1; k < xx.size(); k++) {           if (1LL * (y[i] - yy[j]) * (x[i] - xx[k]) ==               1LL * (y[i] - yy[k]) * (x[i] - xx[j])) {             flag = 0;             break;           }         }       }       if (flag) {         xx.push_back(x[i]);         yy.push_back(y[i]);       }       if (xx.size() == 4) break;     }     if (xx.size() == 2)       printf( YES n );     else if (xx.size() == 3) {       if (check(0, 1, 1, 2) || check(0, 1, 0, 2) || check(0, 2, 1, 2))         printf( YES n );       else         printf( NO n );     } else {       if (check(0, 1, 2, 3) || check(0, 2, 1, 3) || check(0, 3, 1, 2))         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(100, 0);     int b;     for (int i = 0; i < n; i++) {       cin >> b;       b--;       a[b]++;     }     sort(a.begin(), a.end());     int s = 0;     s = a[99] / k;     if (a[99] % k > 0) {       s++;     }     int l = 0;     for (int i = 99; i >= 0; i--) {       if (a[i] > 0) {         l++;       }     }     cout << s * k * l - n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[65];   long long level(long long x) {     int sum = 0;     for (; x != 1; x /= 2) {       sum++;     }     return sum;   }   void write(long long a) {     if (a == 0)       putchar( 0 );     else {       static char c[20];       static int c0;       c0 = 0;       while (a) c[c0++] = a % 10 +  0 , a /= 10;       while (c0--) putchar(c[c0]);     }   }   void get_val(long long x, int l) {     write((x - a[l]) % (1ll << l) + (1ll << l));     putchar(   );     if (x == 1) return;     get_val(x / 2, l - 1);   }   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     int i;     for (i = 0; i < q; i++) {       int t;       cin >> t;       if (t == 1) {         long long x, k;         cin >> x >> k;         x = level(x);         a[x] += k;         a[x] %= (1ll << x);         a[x] += (1ll << x);         a[x] %= (1ll << x);       } else if (t == 2) {         long long x, k;         cin >> x >> k;         x = level(x);         k %= (1ll << x);         for (; x <= 60; x++) {           a[x] += k;           a[x] %= (1ll << x);           a[x] += (1ll << x);           a[x] %= (1ll << x);           k <<= 1;         }       } else {         long long x;         cin >> x;         int k = level(x);         x += a[k];         x %= (1ll << k);         x += (1ll << k);         get_val(x, level(x));         putchar(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T fact(T n) {     return (n == 1 || n == 0) ? 1 : n * fact(n - 1);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   int subarraysum(int arr[], int n, int sum) {     int curr_sum = arr[0], start = 0, i;     for (i = 1; i <= n; i++) {       while (curr_sum > sum && start < i - 1) {         curr_sum = curr_sum - arr[start];         start++;       }       if (curr_sum == sum) {         if (start != i - 1) return 1;       }       if (i < n) curr_sum = curr_sum + arr[i];     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       int c = 0;       for (int i = 0; i < n; i++) {         int x = a[i];         if (subarraysum(a, n, x)) c++;       }       cout << c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 132674 + 10;   int n, len[2];   int R[2][2 * N];   vector<pair<int, int> > open[2 * N], clos[2 * N];   struct Cord {     int x1, asdioayseiowqe12, x2, y2;     Cord() {}     Cord(int x1, int asdioayseiowqe12, int x2, int y2)         : x1(x1), asdioayseiowqe12(asdioayseiowqe12), x2(x2), y2(y2) {}   } C[N];   struct SegmentTree {     int st[4 * 2 * N], lp[4 * 2 * N];     void Propagate(int k) {       if (lp[k] == 0) return;       int v = lp[k];       lp[k] = 0;       st[k << 1] += v;       st[k << 1 | 1] += v;       lp[k << 1] += v;       lp[k << 1 | 1] += v;     }     void Update(int k, int l, int r, int i, int j, int v) {       if (l > j || r < i) return;       if (i <= l && r <= j) {         st[k] += v;         lp[k] += v;         return;       }       Propagate(k);       Update(k << 1, l, ((l + r) >> 1), i, j, v);       Update(k << 1 | 1, ((l + r) >> 1) + 1, r, i, j, v);       st[k] = max(st[k << 1], st[k << 1 | 1]);     }     int Find(int k, int l, int r) {       if (l == r) return l;       Propagate(k);       if (st[k << 1] >= n - 1)         return Find(k << 1, l, ((l + r) >> 1));       else         return Find(k << 1 | 1, ((l + r) >> 1) + 1, r);     }   } ST;   int Pos(int i, int v) {     return lower_bound(R[i] + 1, R[i] + len[i] + 1, v) - R[i];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x1, asdioayseiowqe12, x2, y2;       scanf( %d%d%d%d , &x1, &asdioayseiowqe12, &x2, &y2);       C[i] = Cord(x1, asdioayseiowqe12, x2, y2);       R[0][++len[0]] = x1;       R[0][++len[0]] = x2;       R[1][++len[1]] = asdioayseiowqe12;       R[1][++len[1]] = y2;     }     for (int i = 0; i <= 1; ++i) {       sort(R[i] + 1, R[i] + len[i] + 1);       len[i] = unique(R[i] + 1, R[i] + len[i] + 1) - (R[i] + 1);     }     for (int i = 1; i <= n; ++i) {       int x1 = C[i].x1, asdioayseiowqe12 = C[i].asdioayseiowqe12, x2 = C[i].x2,           y2 = C[i].y2;       int x = Pos(1, asdioayseiowqe12), y = Pos(1, y2);       open[Pos(0, x1)].push_back(pair<int, int>(x, y));       clos[Pos(0, x2)].push_back(pair<int, int>(x, y));     }     for (int i = 1; i <= len[0]; ++i) {       for (int k = 0; k < open[i].size(); ++k) {         int x = open[i][k].first, y = open[i][k].second;         ST.Update(1, 1, len[1], x, y, +1);       }       if (ST.st[1] >= n - 1) {         int j = ST.Find(1, 1, len[1]);         printf( %d %d n , R[0][i], R[1][j]);         return 0;       }       for (int k = 0; k < clos[i].size(); ++k) {         int x = clos[i][k].first, y = clos[i][k].second;         ST.Update(1, 1, len[1], x, y, -1);       }     }     assert(false);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct hh {     int num;     int c;   };   bool cmp(const hh p, const hh q) { return p.c < q.c; }   int main() {     int n, k;     scanf( %d%d , &n, &k);     hh a[1010], b[1010];     int i;     int p = 0, q = 0;     vector<int> ss[1010];     for (i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       if (y == 1) {         a[p].num = i + 1;         a[p++].c = x;       } else {         b[q].num = i + 1;         b[q++].c = x;       }     }     sort(a, a + p, cmp);     sort(b, b + q, cmp);     double ans = 0;     if (p >= k) {       for (i = 1; i < k; ++i) {         ans += a[p - i].c * 1.0 / 2;         ss[i].push_back(a[p - i].num);       }       if (q > 0) {         if (a[0].c > b[0].c) {           ans += b[0].c * 1.0 / 2;           ans += a[0].c;         } else {           ans += a[0].c * 1.0 / 2;           ans += b[0].c;         }         ss[k].push_back(b[0].num);       } else         ans += a[0].c * 1.0 / 2;       ss[k].push_back(a[0].num);       for (i = 1; i < q; ++i) {         ss[k].push_back(b[i].num);         ans += b[i].c;       }       for (i = p - k; i > 0; --i) {         ss[k].push_back(a[i].num);         ans += a[i].c;       }     } else {       for (i = 1; i <= p; ++i) {         ss[i].push_back(a[i - 1].num);         ans += a[i - 1].c * 1.0 / 2;       }       int e = 0;       for (i = p + 1; i <= k; ++i) {         ss[i].push_back(b[e].num);         ans += b[e++].c;       }       for (i = e; i < q; ++i) {         ss[k].push_back(b[i].num);         ans += b[i].c;       }     }     printf( %.1f n , ans);     int j;     for (i = 1; i <= k; ++i) {       printf( %d , ss[i].size());       for (j = 0; j < ss[i].size(); ++j) printf(  %d , ss[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   long long arr[N];   long long pos[N];   long long chance[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, i, j;     long long n;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> arr[i];       pos[arr[i]] = i;     }     long long high = 0, low = 0;     long long ans = 0, ind = 0;     for (i = 1; i <= n; i++) {       if (arr[i] == i) {         high++;       } else if (arr[i] < i) {         high++;         ans += i - arr[i];         chance[arr[i] - i + n]++;       } else {         low++;         ans += arr[i] - i;         chance[arr[i] - i]++;       }     }     long long prev_ans = ans;     for (i = 1; i < n; i++) {       long long lst_elem = arr[n - (i - 1)];       long long cur_ans =           prev_ans + high - 1 - low - abs(n - lst_elem) + abs(1 - lst_elem);       if (cur_ans < ans) {         ans = cur_ans;         ind = i;       }       prev_ans = cur_ans;       high--;       high += chance[i];       low -= chance[i];       low++;     }     cout << ans <<     << ind;   }
#include <bits/stdc++.h>   using namespace std;   char a[502][502];   int n, m;   int ds[502][502][251];   int dfs(int i, int j, int x, int y, int st) {     if (i > x || j > y) {       return 0;     }     if (a[i][j] ==  *  || a[x][y] ==  *  || a[i][j] != a[x][y]) {       return 0;     }     if (ds[i][x][st] != -1) {       return ds[i][x][st];     }     if ((i == x && j == y - 1) || (i == x - 1 && j == y)) {       return 1;     }     if (i == x && j == y) {       return 1;     }     long long int ans = 0;     ans += dfs(i + 1, j, x - 1, y, st + 1);     ans %= 1000000007;     ans += dfs(i, j + 1, x - 1, y, st + 1);     ans %= 1000000007;     ans += dfs(i + 1, j, x, y - 1, st + 1);     ans %= 1000000007;     ans += dfs(i, j + 1, x, y - 1, st + 1);     ans %= 1000000007;     ds[i][x][st] = ans;     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < 502; i++) {       for (int j = 0; j < 502; j++) {         a[i][j] =  * ;         for (int k = 0; k < 251; k++) {           ds[i][j][k] = -1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     int ans = dfs(1, 1, n, m, 0);     ans %= 1000000007;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string vowel =  AEIOUYaeiouy ;     string in;     char s;     bool x = false;     getline(cin, in);     int h = in.size();     for (int k = (h - 1); k >= 0; k--) {       if (isalpha(in[k])) {         s = in[k];         break;       }     }     for (int i = 0; i < vowel.size(); i++) {       if (s == vowel[i]) {         x = true;         break;       }     }     if (x == true)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-5;   const int MOD = int(1e9) + 7, MX = int(5e4) + 1;   long long memo[100][3001][2];   int n, l;   pair<int, int> A[101];   long long dp(int i, int len, int f) {     if (len == l) return 1;     if (i == n || len > l) return 0;     long long &ret = memo[i][len][f];     if (ret + 1) return ret;     ret = 0;     int L = A[i].first, W = A[i].second;     if (f) swap(L, W);     for (int j = 0; j < n; j++) {       if (j != i) {         if (A[j].first == W)           ret += dp(j, len + A[j].first, 0);         else if (A[j].second == W)           ret += dp(j, len + A[j].second, 1);         if (ret >= MOD) ret -= MOD;       }     }     return ret;   }   long long sol() {     memset(memo, -1, sizeof memo);     long long res = 0;     for (int i = 0; i < n; i++) {       res += dp(i, A[i].first, 0) +              (A[i].first - A[i].second ? dp(i, A[i].second, 1) : 0);       if (res >= MOD) res -= MOD;     }     return res;   }   void solve() {     scanf( %d %d , &n, &l);     for (int i = 0; i < n; i++) {       scanf( %d %d , &A[i].first, &A[i].second);     }     printf( %lld n , sol() % MOD);   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const int nmax = 110;   char s[nmax];   bool pal(int n) {     int i;     for (i = 0; i <= (n - 1) / 2; i++)       if (abs(s[i] - s[n - i - 1]) > 2 || abs(s[i] - s[n - i - 1]) == 1) return 0;     return 1;   }   int main() {     int t, n, i;     cin >> t;     for (i = 1; i <= t; i++) {       cin >> n >> s;       if (pal(n) == 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }