malteklaes/cpp-code-code_search_net-style huggingface dataset:
//Iamskk//   #include <iostream>   #include <iosfwd>   #include <iomanip>   #include <cstdio>   #include <cstring>   #include <cstdlib>   #include <ctime>   #include <cmath>   #include <cassert>   #include <cctype>   #include <climits>   #include <vector>   #include <bitset>   #include <set>   #include <queue>   #include <stack>   #include <map>   #include <deque>   #include <string>   #include <list>   #include <iterator>   #include <sstream>   #include <complex>   #include <fstream>   #include <functional>   #include <numeric>   #include <utility>   #include <algorithm>   #include <assert.h>   #include <unordered_map>   using namespace std;   #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);   #define endl   n    #define yes cout<< YES <<endl   #define no cout<< NO <<endl   #define pb push_back   #define all(c) (c).begin(),(c).end()   #define rall(c) (c).rbegin(),(c).rend()   #define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];   #define ao(arr) for(auto asdfasdfasdf:arr) cout<<asdfasdfasdf<<   ;   #define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}   #define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<   ; cout<<endl;}   #define countsetbits(x) __builtin_popcount(x)   #define ll long long   #define debug cout<< I AM EXECUTING <<endl   #define testcases int asdf; cin>>asdf; while(asdf--)   #define vi vector<int>   #define vll vector<long long int>   #define vppo(prs) for(auto x:prs){cout<<x.first<<   <<x.second<<endl;}   #define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)   #define formax 1e18   #define formin -1e18   string sconvert(ll int n)   {    stringstream ss;    ss<<n;    string str = ss.str();    return str;   }   bool sortbysec(const pair<int,int> &a,                  const pair<int,int> &b)    {        return (a.second > b.second);    }      template<typename T>   void imax(T &x,T y){    x = max(x,y);   }   template<typename T>   void imin(T &x,T y){    x = min(x,y);   }   const int nax = 2e3+1;   ll int dp[nax][nax];   vector<ll int> krr;   ll int answer = 0;   ll int solve(int left,int right){    if(dp[left][right]!=-1){     return dp[left][right];    }     if(left>=right){      return 0;     }        ll int value = krr[right]-krr[left];        return dp[left][right]=value + min(solve(left+1,right),solve(left,right-1));           }   void  single()   {    memset(dp,-1,sizeof(dp));    int n;    cin>>n;    vector<ll int> arr(n);    ai(arr,n);    sort(all(arr));    krr = arr;    answer = solve(0,n-1);    cout<<answer<<endl;    // answer = *max_element(all(arr))-*min_element(all(arr));       return;   }   void multiple()   {    testcases       {     single();    }   }      int main()   {     IOS;    // freopen( input.txt , r ,stdin);     //freopen( output.txt , w ,stdout);     single();   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 2e6 + 10;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     if (n == 1 && m == 1) {       cout <<  0 ;       return 0;     }     if (n * m == 2) {       cout <<  4 nUDLR ;       return 0;     }     int t = n - 1 + m - 1 + n * m;     cout << t <<   n ;     for (int i = (0); i < (n - 1); ++i) cout <<  U ;     for (int i = (0); i < (m - 1); ++i) cout <<  L ;     for (int i = (1); i < (n + 1); ++i) {       if (i & 1) {         for (int j = (0); j < (m - 1); ++j) cout <<  R ;         cout <<  D ;       } else {         for (int j = (0); j < (m - 1); ++j) cout <<  L ;         cout <<  D ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[6005], q[6005];   bool check(int a, int b, int x) { return x > a && x < b; }   bool check2(int a, int b, int x) { return x >= a && x <= b; }   bool isOK(int a, int b) { return a == b; }   int sx[1005], sy[1005];   int main() {     int n, t, i, j, a, x, k;     memset(p, 0, sizeof p);     memset(q, 0, sizeof q);     scanf( %d%d , &n, &t);     for (i = 0; i < n; ++i) {       scanf( %d%d , &x, &a);       x *= 2;       sx[i] = x - a;       sy[i] = x + a;       for (j = 6000; j > 0; --j) {         k = -j;         if (p[j] == -1) continue;         if (check2(x - a, x + a, k) || check(x - a, x + a, k - t) ||             check(x - a, x + a, k + t)) {           p[j] = -1;           continue;         }         if (p[j] == 0) {           if (isOK(x - a, k + t) || isOK(x + a, k - t)) {             p[j] = 1;           }         }       }       for (j = 0; j <= 6000; ++j) {         k = j;         if (q[j] == -1) continue;         if (check2(x - a, x + a, k) || check(x - a, x + a, k - t) ||             check(x - a, x + a, k + t)) {           q[j] = -1;           continue;         }         if (q[j] == 0) {           if (isOK(x - a, k + t) || isOK(x + a, k - t)) q[j] = 1;         }       }     }     for (j = 0, i = 1; i <= 6000; ++i)       if (p[i] == 1) {         for (k = 0; k < n; ++k) {           if (check(-i - t, -i + t, sx[k]) || check(-i - t, -i + t, sy[k])) break;         }         if (k == n) ++j;       }     for (i = 0; i <= 6000; ++i)       if (q[i] == 1) {         for (k = 0; k < n; ++k) {           if (check(i - t, i + t, sx[k]) || check(i - t, i + t, sy[k])) break;         }         if (k == n) ++j;       }     printf( %d n , j);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, b;     cin >> n >> b;     std::vector<long long int> v(n);     long long int maxp = 0, minp = 0;     long long int m1, m2 = 0;     for (long long int i = 0; i < n; ++i) {       cin >> v[i];       if (i == 0) m1 = v[i];       if (m2 < v[i]) {         maxp = i;         m2 = v[i];       }       if (m1 > v[i]) {         minp = i;         m1 = v[i];       }     }     std::vector<long long int> v2(v.begin(), v.end());     sort(v2.begin(), v2.end(), greater<long long int>());     long long int currmax = 0, ans = 0;     if (v == v2 || maxp == minp) {       cout << b;     } else {       if (maxp > minp) {         ans = b / m1 * m2 + b % m1;         cout << ans;       } else if (maxp < minp) {         for (long long int i = 0; i < n - 1; ++i) {           long long int maxi = v[i];           for (long long int j = i + 1; j < n; ++j) {             if (v[j] > maxi) {               maxi = v[j];             }           }           ans = b / v[i] * maxi + b % v[i];           if (ans > currmax) {             currmax = ans;           }         }         cout << currmax;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[20001];   struct triplet {     int x, y, z, sum;   };   int a, b, c;   void init() {     for (int i = 1; i <= 20000; ++i) {       for (int j = i; j <= 20000; j += i) v[j].push_back(i);     }   }   triplet calc(int n) {     triplet res;     int ans = 1000000;     for (int fac : v[n]) {       int idx = lower_bound(v[fac].begin(), v[fac].end(), a) - v[fac].begin();       int idx1 = upper_bound(v[fac].begin(), v[fac].end(), a) - v[fac].begin();       if (idx1 != 0) idx1--;       if (abs(v[fac][idx1] - a) < abs(v[fac][idx] - a)) idx = idx1;       int val = abs(v[fac][idx] - a) + abs(fac - b) + abs(n - c);       if (val < ans) {         ans = val;         res.x = v[fac][idx];         res.y = fac;         res.z = n;         res.sum = ans;       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     int tc;     cin >> tc;     while (tc--) {       cin >> a >> b >> c;       int ans = 1000000;       triplet fin;       for (int i = 1; i <= 20000; ++i) {         triplet res = calc(i);         if (res.sum < ans) {           ans = res.sum;           fin.x = res.x;           fin.y = res.y;           fin.z = res.z;           fin.sum = res.sum;         }       }       cout << ans <<   n ;       cout << fin.x <<     << fin.y <<     << fin.z <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     int answer = -1;     long sum_x[2] = {0};     long sum_y[2] = {0};     int nr[2] = {0};     int i;     scanf( %d n , &n);     for (i = 0; i < n; i++) {       int t, x, y;       scanf( %d %d %d n , &t, &x, &y);       if (t == 1) {         sum_x[0] += x;         sum_y[0] += y;         nr[0]++;       } else {         sum_x[1] += x;         sum_y[1] += y;         nr[1]++;       }     }     for (i = 0; i < 2; i++) {       if (sum_x[i] / nr[i] >= 5)         printf( LIVE n );       else         printf( DEAD n );     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int ret = 0;     while (n--) {       char str[1009];       int cnt = 0;       scanf( %s , str);       int flag = 1;       for (int i = 0; str[i]; i++) {         if (str[i] ==  4  || str[i] ==  7 ) {           cnt++;           if (cnt > m) {             flag = 0;             break;           }         }       }       if (flag == 1) {         ret++;       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct query {     int k, pos, ind;   } queries[200005];   struct arr {     int val, ind;   } a[200005];   long long n, q, cnt, res[200005], fw[200005], it[4 * 200005], len, b[200005];   bool cmp(arr a, arr b) {     if (a.val != b.val) return a.val > b.val;     return a.ind < b.ind;   }   bool que(query a, query b) { return a.k < b.k; }   void update(long long k, long long l, long long r, long long id) {     if (l == r) {       it[k] = 1;       return;     }     long long mid = (l + r) / 2;     if (id <= mid)       update(k * 2, l, mid, id);     else       update(k * 2 + 1, mid + 1, r, id);     it[k] = it[k * 2] + it[k * 2 + 1];   }   long long get(long long k, long long l, long long r, long long id) {     if (id > it[k]) return -1;     if (l == r) return l;     long long mid = (l + r) / 2;     if (id <= it[k * 2])       return get(k * 2, l, mid, id);     else       return get(k * 2 + 1, mid + 1, r, id - it[k * 2]);   }   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].val;       a[i].ind = i;       b[i] = a[i].val;     }     sort(a + 1, a + 1 + n, cmp);     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> queries[i].k >> queries[i].pos;       queries[i].ind = i;     }     sort(queries + 1, queries + 1 + q, que);     for (int i = 1; i <= q; i++) {       while (len != queries[i].k) {         len++;         update(1, 1, n, a[len].ind);       }       res[queries[i].ind] = b[get(1, 1, n, queries[i].pos)];     }     for (int i = 1; i <= q; i++) cout << res[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i, j, a[1000005], b[1000005], p = 0, q = 0, m, temp = 0,                                                flag = 0, ans, r = 0, s = 0;     vector<long long> v;     string str;     cin >> n;     map<long long, long long> mp;     while (1) {       if (mp[n] == 1) {         break;       }       mp[n] = 1;       p++;       n++;       while (n % 10 == 0) {         n = n / 10;       }     }     cout << p;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m < n - 1 || m > 2 * (n + 1)) {       printf( -1 n );     } else if (m == n || m == n - 1) {       int flg = 0;       while (m || n) {         if (!flg) {           printf( 0 );           n--;           flg = 1;         } else {           printf( 1 );           m--;           flg = 0;         }       }       printf(  n );     } else if (m == n + 1) {       while (n) {         printf( 10 );         n -= 1;       }       printf( 1 n );     } else {       while (m != n && n > 0) {         printf( 110 );         m -= 2;         n -= 1;       }       if (n == 0) {         while (m--) {           printf( 1 );         }       } else {         while (n--) {           printf( 10 );         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10000] = {0}, b[10000] = {0}, n, k, dem = 0;   int main() {     cin >> n >> k;     for (int i = (1), _b = (k); i <= _b; i++) {       cin >> a[i];       b[a[i]] = i;     }     for (int i = (1), _b = (k); i <= _b; i++) {       dem = 1;       cout << a[i];       for (int j = (1), _b = (n * k); j <= _b; j++)         if (b[j] == 0) {           dem++;           cout <<     << j;           b[j] = i;           if (dem == n) break;         }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 99999999999999999;   long long n, value[200000], zarib[200000], LCM = 1, GCD, x = INF, ans, sum;   vector<int> Tree[200000];   long long gcd(long long l, long long r) {     if (!l) return r;     return gcd(r % l, l);   }   bool dfs(int v, int last, long long z) {     zarib[v] = z;     if (v && Tree[v].size() == 1 && zarib[v] > sum) return 0;     z *= (Tree[v].size() - 1);     if (!z) z = 1;     for (int i = 0; i < Tree[v].size(); i++)       if (Tree[v][i] != last)         if (!dfs(Tree[v][i], v, z)) return 0;     return 1;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> value[i];       sum += value[i];     }     for (int i = 1; i < n; i++) {       int l, r;       cin >> l >> r;       Tree[l - 1].push_back(r - 1);       Tree[r - 1].push_back(l - 1);     }     if (!dfs(0, -1, 1)) {       cout << sum << endl;       return 0;     }     for (int i = 1; i < n; i++)       if (Tree[i].size() == 1) {         GCD = gcd(LCM, zarib[i]);         LCM /= GCD;         LCM *= zarib[i];       }     for (int i = 1; i < n; i++)       if (Tree[i].size() == 1) {         zarib[i] = LCM / zarib[i];         x = min(x, value[i] / zarib[i]);       }     for (int i = 1; i < n; i++)       if (Tree[i].size() == 1) ans += value[i] - zarib[i] * x;     cout << ans << endl;   }
#include <bits/stdc++.h>   const int maxn = 100001;   int n, i, u, v, top, a[maxn], spt[maxn], vt[maxn], st[maxn], l[maxn];   long long sum, ans, tmp, val[maxn], uc, bc, ss, min;   std::vector<int> adj[maxn];   void dfs() {     top = 1;     st[1] = 1;     while (top > 0) {       u = st[top];       if (vt[u] < spt[u] && adj[u][vt[u]] == st[top - 1]) vt[u]++;       if (vt[u] < spt[u]) {         if (u == 1)           tmp *= spt[u];         else           tmp *= (spt[u] - 1);         if (tmp > sum) {           ans = -1;           return;         }         st[++top] = adj[u][vt[u]];         vt[u]++;       } else {         if (spt[u] == 1 && u != 1) {           val[u] = tmp;           uc = tmp;           l[++l[0]] = u;         }         top--;         if (st[top] == 1)           tmp /= spt[st[top]];         else           tmp /= (spt[st[top]] - 1);       }     }   }   long long ucln(long long a, long long b) {     while (a > 0 && b > 0)       if (a > b)         a %= b;       else         b %= a;     if (a > 0)       return a;     else       return b;   }   int main() {     std::cin >> n;     for (i = 1; i <= n; i++) {       std::cin >> a[i];       sum += a[i];     }     for (i = 1; i < n; i++) {       std::cin >> u >> v;       spt[u]++;       spt[v]++;       adj[u].push_back(v);       adj[v].push_back(u);     }     tmp = 1;     dfs();     if (ans == -1) {       std::cout << sum;       return 0;     }     bc = val[l[1]];     for (i = 2; i <= l[0]; i++) {       uc = ucln(bc, val[l[i]]);       bc /= uc;       if (bc > double(sum) / val[i]) {         std::cout << sum;         return 0;       }       bc *= val[l[i]];     }     min = 1000000000000000000;     for (i = 1; i <= l[0]; i++) {       val[l[i]] = bc / val[l[i]];       if (min > a[l[i]] / val[l[i]]) min = a[l[i]] / val[l[i]];     }     if (min == 0) {       std::cout << sum;       return 0;     }     for (i = 1; i <= l[0]; i++) ans += a[l[i]] - val[l[i]] * min;     std::cout << ans;     return 0;   }
#include <bits/stdc++.h>   int value(const std::vector<int>& xs, int base, int i) {     return (xs[(base + i) % xs.size()] + 10 - xs[base]) % 10;   }   bool lt(const std::vector<int>& xs, int a, int b) {     int N = xs.size();     for (int i = 0; i < N; ++i) {       int va = value(xs, a, i), vb = value(xs, b, i);       if (va != vb) return va < vb;     }     return false;   }   int main() {     int N;     std::cin >> N;     std::string s;     std::cin >> s;     std::vector<int> xs(N), is(N);     for (int i = 0; i < N; ++i) xs[i] = s[i] -  0 , is[i] = i;     std::sort(is.begin(), is.end(), [&](int a, int b) { return lt(xs, a, b); });     for (int i = 0; i < N; ++i) std::cout << value(xs, is[0], i);     std::cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int long long n, a[60], mx = 2000;       scanf( %lld , &n);       for (int i = 0; i < n; i++) {         scanf( %lld , &a[i]);       }       sort(a, a + n);       for (int i = 1; i < n; i++) {         mx = min(mx, abs(a[i - 1] - a[i]));       }       printf( %lld n , mx);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   long long f[N], g[N], a[N], ans;   int n, F1, F2, F3, F4, F5, F6, k;   inline void upd(long long &x, long long y) {     if (x < y) x = y;   }   inline int calc(int y, int x) {     if (x * 9 < y) return -1e9;     if (y % 3 == 0) return y / 3;     if ((x - 1) * 9 >= y) return y / 3;     return (y / 9) * 3;   }   int main() {     scanf( %d , &n);     scanf( %d%d%d%d%d%d , &F1, &F2, &F3, &F4, &F5, &F6);     scanf( %d , &k);     scanf( %d , &k);     for (int i = 0; i <= 9; i++) f[i] = (long long)calc(i, n) * F6;     for (int i = 0; i < N; i++) g[i] = -1e18;     for (int i = 0; i <= 99; i++) a[i] = (long long)calc(i, n) * F5;     for (int i = 0; i <= 9; i++) {       const int x = i * 10;       for (int j = 0; j <= 99 - x; j++) upd(g[x + j], f[i] + a[j]);     }     for (int i = 0; i <= 99; i++) f[i] = g[i], g[i] = -1e18;     for (int i = 0; i <= 999; i++) a[i] = (long long)calc(i, n) * F4;     for (int i = 0; i <= 99; i++) {       const int x = i * 10;       for (int j = 0; j <= 999 - x; j++) upd(g[x + j], f[i] + a[j]);     }     for (int i = 0; i <= 999; i++) f[i] = g[i], g[i] = -1e18;     for (int i = 0; i <= 9999; i++) a[i] = (long long)calc(i, n) * F3;     for (int i = 0; i <= 999; i++) {       const int x = i * 10;       for (int j = 0; j <= 9999 - x; j++) upd(g[x + j], f[i] + a[j]);     }     for (int i = 0; i <= 9999; i++) f[i] = g[i], g[i] = -1e18;     for (int i = 0; i <= 99999; i++) a[i] = (long long)calc(i, n) * F2;     for (int i = 0; i <= 9999; i++) {       const int x = i * 10;       for (int j = 0; j <= 99999 - x; j++) upd(g[x + j], f[i] + a[j]);     }     for (int i = 0; i <= 99999; i++) f[i] = g[i], g[i] = -1e18;     for (int i = 0; i <= k; i++) a[i] = (long long)calc(i, n) * F1;     for (int i = 0; i <= k / 10; i++) upd(ans, a[k - i * 10] + f[i]);     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b) {       int r = a % b;       a = b;       b = r;     }     return a;   }   int64_t lcm(int a, int b) { return 1LL * a * b / gcd(a, b); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> next(n + 1);     for (int i = 1; i <= n; i++) cin >> next[i];     int64_t ans = 1;     vector<bool> cycle(n + 1);     for (int i = 1; i <= n; i++)       if (!cycle[i]) {         int node = i;         vector<int> vis(n + 1);         for (int j = 0; j < n + 1; j++) {           vis[node]++;           node = next[node];         }         if (vis[i] >= 2) {           int len = 0, node = i;           while (!cycle[node]) {             len++;             cycle[node] = true;             node = next[node];           }           ans = lcm(ans, len);         }       }     int mx = 0;     for (int i = 1; i <= n; i++)       if (!cycle[i]) {         int dist = 0, node = i;         while (!cycle[node]) {           dist++;           node = next[node];         }         mx = max(mx, dist);       }     int it = 1;     while (it * ans < mx) it++;     cout << it * ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 1;     while (t--) {       int n, k, inits[26];       char str[101];       bool poss = false, started[26] = {false};       scanf( %d%s , &k, str);       n = strlen(str);       if (n < k) {         puts( NO );         break;       }       int cnt = 0;       for (int i = 0, j = 0; i < n; i++) {         if (!started[str[i] -  a ]) {           started[str[i] -  a ] = 1;           cnt++;           inits[j] = i;           j++;         }         if (cnt == k) {           poss = true;           break;         }       }       if (!poss)         puts( NO );       else {         puts( YES );         int i = 0;         for (int j = 0; j < n; j++) {           if (j == inits[i + 1] - 1) {             printf( %c n , str[j]);             i++;           } else             printf( %c , str[j]);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int flag0 = 0, flag2 = 0, sum = 0;       for (long long int i = 0; i < s.length(); i++) {         if ((s[i] ==  0 ) && (flag0 == 0))           flag0 = 1;         else if (int(s[i] -  0 ) % 2 == 0)           flag2 = 1;         sum += int(s[i] -  0 );       }       if ((flag0) && (flag2) && (sum % 3 == 0))         cout <<  red               <<   n ;       else         cout <<  cyan               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000;   const long long MOD = 1000000007;   long long D[maxn][maxn];   long long n, k;   int main() {     cin >> n >> k;     D[0][0] = 1;     --k;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       D[(1 << k)][i + 1] = D[(1 << k)][i];       if (x == 0) {         D[(1 << k)][i + 1] += D[(1 << k)][i];         D[(1 << k)][i + 1] %= MOD;       }       for (int msk = 0; msk < (1 << k); ++msk) {         int n_msk = msk;         if (x == 4 || x == 0) {           if ((msk & 1) == 1) {             n_msk = 0;             n_msk |= (1 << 1);           } else {             int u = 1;             while (u <= k && ((n_msk & (1 << u)) != 0)) {               n_msk ^= (1 << u);               ++u;             }             n_msk ^= (1 << u);           }           D[n_msk][i + 1] += D[msk][i];           D[n_msk][i + 1] %= MOD;         }         if (x == 2 || x == 0) {           int n_msk = msk;           int u = 0;           while (u <= k && ((n_msk & (1 << u)) != 0)) {             n_msk ^= (1 << u);             ++u;           }           n_msk ^= (1 << u);           D[n_msk][i + 1] += D[msk][i];           D[n_msk][i + 1] %= MOD;         }       }     }     cout << D[(1 << k)][n] % MOD << endl;   }