malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int d, m, n, x[25], a[30005];   vector<long long> ok;   long long L, R;   map<long long, vector<long long> > ans;   map<long long, vector<long long> > zip;   vector<long long> calc(long long lim) {     if (zip.find(lim) != zip.end()) return zip[lim];     vector<long long> ret(m, 0);     if (lim == 0) {       ret[0] = 1;       return ret;     }     for (int beg = 0; beg < d && beg <= lim; beg++) {       long long nxt_lim = (lim - beg) / d;       vector<long long> R = calc(nxt_lim);       for (int i = 0; i < m; i++) {         int a = (i + x[beg]);         if (a >= m) a -= m;         ret[a] += R[i];       }     }     return zip[lim] = ret;   }   void rec(long long lim, vector<long long> mask, bool F) {     if (mask.size() == 1) {       if (ans.find(lim) == ans.end()) {         ans[lim] = vector<long long>(m, 0);       }       for (int i = 0; i < m; i++) {         if (((mask[0] >> i) & 1LL)) {           if (F)             ans[lim][i]++;           else             ans[lim][i]--;         }       }       return;     }     for (int beg = 0; beg < d && beg <= lim; beg++) {       long long nxt_lim = (lim - beg) / d;       vector<long long> vec;       int zan = mask.size();       int bb = (d - beg);       int xx = 1 + (zan - bb + d - 1) / d;       vec.resize(xx, 0LL);       long long B = (1LL << m) - 1;       int cur = beg;       int id = 0;       for (int i = 0; i < mask.size(); i++) {         int add = x[cur];         long long nw = 0;         nw = (mask[i] >> add) | (mask[i] << (m - add));         B &= nw;         if (cur == d - 1 || i == mask.size() - 1) {           vec[id++] = B;           B = (1LL << m) - 1;         }         cur++;         if (cur == d) cur = 0;       }       assert(id == xx);       rec(nxt_lim, vec, F);     }   }   int main() {     cin >> d >> m;     for (int i = 0; i < d; i++) {       cin >> x[i];     }     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       ok.push_back((2LL << a[i]) - 1LL);     }     cin >> L >> R;     L--;     R--;     rec(R - n + 1, ok, true);     if (L - 1 >= 0) rec(L - 1, ok, false);     long long ret = 0;     for (map<long long, vector<long long> >::iterator it = ans.begin();          it != ans.end(); it++) {       vector<long long> tbl = calc(it->first);       for (int i = 0; i < m; i++) {         ret += tbl[i] * it->second[i];       }     }     cout << ret << endl;   }
#include <bits/stdc++.h>   int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }   long long pow(long long a, int p) {     long long ans = 1;     while (p) {       if (p & 1) ans *= a;       a *= a;       p >>= 1;     }     return ans;   }   int main() {     int n, l, r;     scanf( %d%d%d , &n, &l, &r);     if (n == 1) {       printf( %d n , r - l + 1);       return 0;     }     if (n == 2) {       printf( %lld n , (long long)(r - l + 1) * (r - l));       return 0;     }     if (n > 30) {       printf( 0 n );       return 0;     }     n--;     int M = 1;     while (pow(M + 1, n) <= r) M++;     long long ans = 0;     for (int y = 1; y <= M; y++) {       for (int x = y + 1; x <= M; x++)         if (gcd(x, y) == 1) {           int py = pow(y, n), px = pow(x, n);           int L = 1, R = l / py + 1;           int RR = r / px;           while (L < R) {             int M = (L + R) / 2;             if (M * py < l)               L = M + 1;             else               R = M;           }           if (L <= RR) ans += RR - L + 1;         }     }     printf( %lld n , ans << 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int n, m;     cin >> n >> m;     long long int a[n], b[m];     long long int aux[n];     for (long long int i = 0; i < n; ++i) {       cin >> a[i];       if (i == 0)         aux[i] = a[i];       else         aux[i] = aux[i - 1] + a[i];     }     for (long long int i = 0; i < m; ++i) cin >> b[i];     long long int j = 0;     for (long long int i = 0; i < m; ++i) {       while (j < n && aux[j] < b[i]) ++j;       if (j == 0)         cout << j + 1 <<     << b[i] << endl;       else         cout << j + 1 <<     << b[i] - aux[j - 1] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   set<long long> bms[6];   long long to_bit(string &s) {     long long x = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  0 ) continue;       x |= (1LL << i);     }     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     bms[0].insert(0);     for (int j = 1; j <= n; j++) {       for (int i = min(j, 5); i >= 1; i--) {         for (long long x : bms[i - 1]) {           bms[i].insert(x | (1LL << (j - 1)));         }       }     }     int c;     long long x;     string s;     set<long long> poss;     cin >> s >> c;     x = to_bit(s);     for (long long bm : bms[c]) {       poss.insert(~(x ^ bm));     }     for (int i = 1; i < m; i++) {       cin >> s >> c;       x = to_bit(s);       set<long long> tposs;       for (long long bm : bms[c]) {         if (!poss.count(~(x ^ bm))) continue;         tposs.insert(~(x ^ bm));       }       poss = tposs;     }     cout << poss.size() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int g[100000], cnt[100000];   int v[100000], b[100000];   int s[100005], sc[100005], sz;   bool used[100005] = {}, dead[100005] = {}, marked[100005] = {};   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(n); ++i) scanf( %d , g + i), --g[i], cnt[i] = 1;     for (int i = 0; i < (int)(m); ++i) scanf( %d , v + i);     for (int i = 0; i < (int)(m); ++i) scanf( %d , b + i);     int prevAns = 0;     for (int q = 0; q < (int)(m); ++q) {       int a = (v[q] + prevAns - 1) % n;       int ans = 0;       int rem = b[q];       --rem;       if (!used[a]) {         ans = 1;         used[a] = true;       }       while (true) {         sz = 0;         while (used[g[a]]) {           if (marked[a] || dead[a]) break;           s[sz] = a;           marked[a] = true;           rem -= cnt[a];           a = g[a];           ++sz;         }         if (marked[a] || dead[a]) {           for (int i = 0; i < (int)(sz); ++i) dead[s[i]] = true;           for (int i = 0; i < (int)(sz); ++i) marked[s[i]] = false;           break;         }         for (int i = 0; i < (int)(sz); ++i) marked[s[i]] = false;         for (int i = sz - 1; i >= 0; --i) {           cnt[s[i]] += cnt[g[s[i]]];           g[s[i]] = g[g[s[i]]];         }         rem -= cnt[a];         if (rem < 0) {           break;         }         a = g[a];         used[a] = true;         ++ans;       }       printf( %d n , ans);       prevAns = ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   int a[MAXN];   int b[MAXN];   int tmp[MAXN];   int main() {     int n;     cin >> n;     int aidx;     for (int i = 0; i < n; i++) {       cin >> tmp[i];       if (tmp[i] == 0) aidx = i;     }     for (int i = 0; i < n; i++) a[i] = tmp[(i + aidx) % n];     int bidx;     for (int i = 0; i < n; i++) {       cin >> tmp[i];       if (tmp[i] == 0) bidx = i;     }     for (int i = 0; i < n; i++) b[i] = tmp[(i + bidx) % n];     for (int i = 0; i < n - 1; i++) {       a[i] = a[i + 1];       b[i] = b[i + 1];     }     for (int i = 0; i < n - 1; i++)       if (b[i] == a[0]) bidx = i;     for (int i = 0; i < n - 1; i++)       if (a[i] != b[(i + bidx) % (n - 1)]) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-11;   const int INF = 101e7;   template <class T>   T sqr(T first) {     return first * first;   }   template <class T>   T abs(T first) {     return (first < 0) ? -first : first;   }   int main() {     int n, m, h;     cin >> n >> m >> h;     n--;     int sh = 0, sum = 0;     for (int _b = (m), i = (1); i <= _b; i++) {       if (i == h) {         cin >> sh;         sh--;       } else {         int k;         cin >> k;         sum += k;       }     }     if (n > sh + sum) {       cout <<  -1 n ;       return 0;     }     double c = 1;     for (int i = 0, _n = (n); i < _n; i++) {       c *= (double(sum) / (sum + sh));       sum--;     }     printf( %.8f n , 1 - c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long k;     cin >> k;     long long i = 0, prev = 0;     while (k > prev + (9 * pow(10, i) * (i + 1))) {       prev += 9 * pow(10, i) * (i + 1);       i++;     }     k -= prev;     long long temp;     temp = pow(10, i) + (k / (i + 1)) - 1;     if (k % (i + 1) != 0) {       temp++;     }     if (k % (i + 1) == 0) {       cout << temp % 10 <<   n ;     } else {       long long ans = temp / pow(10, i + 1 - (k % (i + 1)));       ans %= 10;       cout << ans <<   n ;     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int64_t N = 1e3 + 5, M = 1e9 + 7;   int64_t a[N][N];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int64_t n, m, s = 0;     cin >> n >> m;     for (int64_t i = 0; i < n; i++)       for (int64_t j = 0; j < m; j++) cin >> a[i][j];     for (int64_t i = n - 2; i; i--)       for (int64_t j = m - 2; j; j--)         if (!a[i][j]) a[i][j] = min(a[i + 1][j], a[i][j + 1]) - 1;     for (int64_t i = 0; i < n; i++)       for (int64_t j = 1; j < m; j++)         if (a[i][j] <= a[i][j - 1]) return cout << -1, 0;     for (int64_t j = 0; j < m; j++)       for (int64_t i = 1; i < n; i++)         if (a[i][j] <= a[i - 1][j]) return cout << -1, 0;     for (int64_t i = 0; i < n; i++)       for (int64_t j = 0; j < m; j++) s += a[i][j];     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5;   long long line[maxn];   int sum, q1, q2;   int flag1, k, qw, wa, flag2;   int main() {     int n, zz = 1;     cin >> n;     for (int i = (int)(1); i < (int)(n + 1); i++) cin >> line[i];     while (zz <= n) {       q1 = 0, q2 = 0, flag1 = 0, k = 0, wa = 0, flag2 = 0;       sum++;       for (int i = (int)(zz); i < (int)(n + 1); i++) {         qw = i;         if (line[i] != -1 && flag1 == 0) {           q1 = line[i];           flag1 = 1;           continue;         }         if (flag1 == 1 && line[i] == -1) {           k++;           continue;         }         if (line[i] == -1 && flag1 == 0) {           wa++;           continue;         }         if (line[i] != -1 && flag1 == 1) {           q2 = line[i];           flag2 = 1;           break;         }       }       zz = qw;       if (qw > n) break;       if (qw == n && (flag2 == 0 || flag1 == 0)) break;       if ((q2 - q1) % (k + 1) != 0) continue;       long long d = (q2 - q1) / (k + 1);       if (q1 - wa * d <= 0) continue;       zz = qw + 1;       while (zz <= n) {         if (line[zz] == -1) {           if (line[zz - 1] + d <= 0) break;           line[zz] = line[zz - 1] + d;           zz++;         } else {           if (line[zz] - line[zz - 1] != d) break;           zz++;         }       }     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b = 1, c, can[100000 * 10], cc, M, tmp[100000 * 10],                      ans = 0x3f3f3f3f3f3f3f3f, XH;   inline long long cheng(long long u, long long v) {     long long res = 0;     for (; v; v >>= 1) {       if (v & 1) res = (res + u) % M;       u = u * 2 % M;     }     return res;   }   struct Jz {     long long num[2][2];     Jz() { memset(num, 0, sizeof(num)); }     Jz operator*(const Jz &u) const {       Jz res;       long long i, j, k;       for (i = 0; i < 2; i++) {         for (j = 0; j < 2; j++) {           for (k = 0; k < 2; k++) {             res.num[i][j] = (res.num[i][j] + cheng(num[i][k], u.num[k][j])) % M;           }         }       }       return res;     }   } dw;   inline Jz po(Jz u, long long v) {     Jz res;     res.num[0][0] = res.num[1][1] = 1;     for (; v;) {       if (v & 1) res = res * u;       u = u * u;       v >>= 1;     }     return res;   }   inline long long ask(long long u) {     Jz res = po(dw, u);     return res.num[0][0];   }   int main() {     dw.num[0][1] = dw.num[1][0] = dw.num[1][1] = 1;     long long i, j, k, t;     cin >> n;     t = n % 100000;     for (i = 1;; i++) {       if (t == a) can[++cc] = i;       c = (a + b) % 100000;       a = b, b = c;       if (!a && b == 1) break;     }     for (M = 100000 * 10, XH = 150000; M <= (long long)1e13; M *= 10, XH *= 10) {       t = n % M, k = 0;       for (i = 1; i <= cc; i++) {         for (j = 0; j <= 9; j++) {           if (ask(can[i] + XH * j) % M == t) {             tmp[++k] = can[i] + XH * j;           }         }       }       for (i = 1; i <= k; i++) can[i] = tmp[i];       cc = k;     }     if (!cc) {       puts( -1 );       return 0;     }     for (i = 1; i <= cc; i++) ans = min(ans, can[i]);     cout << ans - 1;   }
#include <bits/stdc++.h>   using namespace std;   int store[20][1 << 20];   struct trie {     int k;     struct Node {       Node* ch[2];       Node() { ch[0] = ch[1] = NULL; }     };     Node* root;     trie(int k) : k(k) { root = new Node(); }     void insert(int x) {       Node* cur = root;       for (int i = k - 1; i >= 0; i--) {         int side = x >> i & 1;         if (!cur->ch[side]) cur->ch[side] = new Node();         cur = cur->ch[side];       }     }     void eval() {       vector<int> ret(1 << k);       for (int i = 0; i <= k; i++) fill(store[i], store[i] + (1 << k), 1 << 30);       function<vector<pair<int, int> >(Node*, int)> dfs = [&](Node* node, int h) {         if (!node) return vector<pair<int, int> >();         if (h == 0) {           vector<pair<int, int> > ret = {{0, 0}};           return ret;         }         vector<pair<int, int> > A = dfs(node->ch[0], h - 1),                                 B = dfs(node->ch[1], h - 1);         vector<pair<int, int> > ret(1 << h);         for (int x = 0; x < (1 << h); x++) {           int add = 1 << (h - 1);           int rem = x & (add - 1);           if (x >> (h - 1) & 1) {             ret[x].first = node->ch[1] ? B[rem].first : A[rem].first + add;             ret[x].second = node->ch[0] ? A[rem].second + add : B[rem].second;           } else {             ret[x].first = node->ch[0] ? A[rem].first : B[rem].first + add;             ret[x].second = node->ch[1] ? B[rem].second + add : A[rem].second;           }           if (!A.empty() && !B.empty()) {             if (x >> (h - 1) & 1)               store[h][x] = min(store[h][x], A[rem].first + add - B[rem].second);             else               store[h][x] = min(store[h][x], B[rem].first + add - A[rem].second);           }           assert(max(ret[x].first, ret[x].second) < (1 << h) &&                  min(ret[x].first, ret[x].second) >= 0);         }         return ret;       };       dfs(root, k);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     trie T(k);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       T.insert(x);     }     T.eval();     for (int x = 0; x < (1 << k); x++) {       int ans = 1 << 30;       for (int h = k; h; h--) {         ans = min(ans, store[h][x & ((1 << h) - 1)]);       }       cout << ans <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101], x = 0;     string s1, s2;     cin >> s1 >> s2;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] != s2[i])         a[i] = 1;       else         a[i] = 0;       x++;     }     for (int i = 0; i < x; i++) {       cout << a[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct app {     int x, y;   };   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int m1, m2;     vector<app> arr(n);     for (__typeof(0) i = 0; i <= n - 1; i++) {       scanf( %d , &arr[i].x);       scanf( %d , &arr[i].y);       if (i == 0) {         m1 = arr[i].x;         m2 = arr[i].y;       } else {         if (arr[i].x * m2 < arr[i].y * m1) {           m1 = arr[i].x;           m2 = arr[i].y;         }       }     }     double ans = m * m1;     ans = ans * 1.0 / m2 * 1.0;     cout << fixed << setprecision(8) << ans;     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   const int MOD = 1000003;   int R, C;   char *grid[600000];   int main() {     scanf( %d%d , &R, &C);     for (int i = (0); i < (R); i++) {       grid[i] = new char[C + 5];       scanf( %s , grid[i]);     }     int res = 1;     for (int i = (0); i < (R); i++) {       int b1 = 1, b2 = 1;       for (int j = (0); j < (C); j++) {         if (grid[i][j] ==  1  || grid[i][j] ==  2 ) {           if (j % 2) {             b1 = 0;           } else {             b2 = 0;           }         } else if (grid[i][j] ==  3  || grid[i][j] ==  4 ) {           if (j % 2) {             b2 = 0;           } else {             b1 = 0;           }         }       }       res = (res * (b1 + b2)) % MOD;     }     for (int j = (0); j < (C); j++) {       int b1 = 1, b2 = 1;       for (int i = (0); i < (R); i++) {         if (grid[i][j] ==  1  || grid[i][j] ==  4 ) {           if (i % 2) {             b1 = 0;           } else {             b2 = 0;           }         } else if (grid[i][j] ==  2  || grid[i][j] ==  3 ) {           if (i % 2) {             b2 = 0;           } else {             b1 = 0;           }         }       }       res = (res * (b1 + b2)) % MOD;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n;     cin >> n;     long long s = 0;     for (int i = 0; i < n; ++i) {       long long x;       cin >> x;       s += x;     }     long long add = (s - n * (n - 1) / 2) / n;     long long cnt = s - (n * (n - 1) / 2 + add * n);     for (int i = 0; i < n; ++i) {       cout << i + add + int(i < cnt) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, maxn = 2e3 + 5;   long long f[maxn][maxn][2][2];   long long g[maxn];   long long n, m;   long long upd(const long long &x) {     if (x < 0) return x + mod;     if (x >= mod) return x - mod;     return x;   }   void add(long long &x, const long long &y) { x = upd(x + upd(y)); }   long long jc[maxn], inv[maxn];   long long ksm(long long x, long long k) {     long long ans = 1;     while (k) {       if (k & 1) ans = ans * x % mod;       x = x * x % mod;       k >>= 1;     }     return ans;   }   void init(long long n) {     jc[0] = 1;     for (long long i(1), endi(n); i <= endi; i++) jc[i] = jc[i - 1] * i % mod;     inv[n] = ksm(jc[n], mod - 2);     for (long long i(n - 1), endi(0); i >= endi; i--)       inv[i] = inv[i + 1] * (i + 1) % mod;   }   long long C(long long n, long long m) {     if (n < 0 || m < 0 || n < m) return 0;     return jc[n] * inv[m] % mod * inv[n - m] % mod;   }   signed main() {     scanf( %lld%lld , &n, &m);     init(n);     f[1][0][0][0] = 1;     f[1][1][0][1] = 1;     for (long long i(2), endi(n); i <= endi; i++)       for (long long j(0), endj(n); j <= endj; j++) {         if (j) {           add(f[i][j][0][0], f[i - 1][j - 1][0][0]);           add(f[i][j][1][0], f[i - 1][j - 1][0][1]);           if (i != n) {             add(f[i][j][0][1], f[i - 1][j - 1][0][0] + f[i - 1][j - 1][1][0]);             add(f[i][j][1][1], f[i - 1][j - 1][0][1] + f[i - 1][j - 1][1][1]);           }         }         add(f[i][j][0][0], f[i - 1][j][0][0] + f[i - 1][j][1][0]);         add(f[i][j][1][0], f[i - 1][j][0][1] + f[i - 1][j][1][1]);       }     for (long long i(0), endi(n); i <= endi; i++) {       add(g[i], f[n][i][0][0] + f[n][i][1][0]);       g[i] = g[i] * jc[n - i] % mod;     }     long long ans = 0;     for (long long i(m), endi(n); i <= endi; i++) {       add(ans, ((i - m) & 1 ? -1 : 1) * g[i] * C(i, m) % mod);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chmax(T &x, const T &y) {     return (x < y) ? (x = y, true) : false;   };   template <typename T>   bool chmin(T &x, const T &y) {     return (x > y) ? (x = y, true) : false;   };   constexpr long long int MOD = 10;   constexpr long long int INF = 2e18;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<long long int> p(n);       for (long long int i = 0; i < (n); i++) cin >> p[i], p[i]--;       vector<long long int> cnt(n, 0);       for (long long int i = 0; i < (n); i++) {         cnt[(p[i] - i + n) % n]++;       }       vector<long long int> ans;       for (long long int i = 0; i < (n); i++) {         if (n - cnt[i] <= m) {           ans.push_back((-i + n) % n);         } else if (n - cnt[i] <= m * 2) {           int x = 0;           vector<long long int> q(n);           for (long long int j = 0; j < (n); j++) q[j] = p[(j - i + n) % n];           vector<long long int> f(n, 0);           for (long long int j = 0; j < (n); j++) {             if (f[j] == 0) {               int now = j;               while (f[now] == 0) {                 f[now] = 1;                 now = q[now];                 x++;               }               x--;             }           }           if (x <= m) ans.push_back((-i + n) % n);         }       }       sort(ans.begin(), ans.end());       cout << ans.size();       for (auto i : ans) cout <<     << i;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int K = 998244353;   long long int mu(long long int a, long long int n) {     if (n == 0) return 1;     long long int q = mu(a, n / 2);     if (n % 2 == 0) return q * q % K;     return q * q % K * a % K;   }   long long int d[55][55][55][55], inv[5305];   int isLiked[55], weight[55];   int n, m, total;   long long int a, b;   long long int calc(int w, int A, int B, int m, int i) {     if (w * isLiked[i] + weight[i] < 0 || A + a < 0 || b - B < 0) return 0;     if (m == 0) {       return w * isLiked[i] + weight[i];     }     if (d[w][A][B][m] != -1) return d[w][A][B][m];     long long int deno = inv[w * isLiked[i] + A - B + weight[i] + a + b];     long long int res = 0;     res += (A + a) * calc(w, A + 1, B, m - 1, i) % K;     res %= K;     res += (b - B) * calc(w, A, B + 1, m - 1, i) % K;     res %= K;     res += (weight[i] + w * isLiked[i]) * calc(w + 1, A, B, m - 1, i) % K;     res %= K;     res = res * deno % K;     return d[w][A][B][m] = res % K;   }   long long int solve(int i) {     memset(d, -1, sizeof(d));     a = 0, b = 0;     for (int j = 1; j <= n; j++) {       if (j == i) continue;       if (isLiked[j] == 1) {         a += weight[j];       } else {         b += weight[j];       }     }     return calc(0, 0, 0, m, i);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     for (int i = 1; i <= 5300; i++) {       inv[i] = mu(i, K - 2);     }     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> isLiked[i];       if (!isLiked[i]) isLiked[i] = -1;     }     for (int i = 1; i <= n; i++) {       cin >> weight[i];     }     for (int i = 1; i <= n; i++) {       cout << solve(i) << endl;     }     return 0;   }