malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int cnt2[maxn];   int cnt[maxn];   struct trie {     int nxt[maxn][26], fail[maxn], g[maxn];     int ed[maxn];     int rt, L;     int newnode() {       memset(nxt[L], -1, sizeof nxt[L]);       ed[L++] = 0;       return L - 1;     }     void init() {       L = 0;       rt = newnode();     }     void insert(const string& buf) {       int len = buf.size();       int now = rt;       for (int i = 0; i < len; ++i) {         if (nxt[now][buf[i] -  a ] == -1) nxt[now][buf[i] -  a ] = newnode();         now = nxt[now][buf[i] -  a ];       }       ed[now]++;     }     void build() {       queue<int> q;       fail[rt] = rt;       g[rt] = rt;       for (int i = 0; i < 26; ++i) {         if (nxt[rt][i] == -1)           nxt[rt][i] = rt;         else {           fail[nxt[rt][i]] = rt;           g[nxt[rt][i]] = rt;           q.push(nxt[rt][i]);         }       }       while (!q.empty()) {         int now = q.front();         q.pop();         for (int i = 0; i < 26; ++i) {           if (nxt[now][i] == -1)             nxt[now][i] = nxt[fail[now]][i];           else {             fail[nxt[now][i]] = nxt[fail[now]][i];             if (ed[fail[nxt[now][i]]]) {               g[nxt[now][i]] = fail[nxt[now][i]];             } else               g[nxt[now][i]] = g[fail[nxt[now][i]]];             q.push(nxt[now][i]);           }         }       }     }     void query(const string& buf) {       int len = buf.size();       int now = rt;       for (int i = 0; i < len; ++i) {         now = nxt[now][buf[i] -  a ];         int tmp = now;         while (tmp != rt) {           cnt[i] += ed[tmp];           tmp = g[tmp];         }       }     }   } a, b;   string t;   string s[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     int n;     cin >> n;     a.init();     for (int i = 1; i <= n; ++i) {       cin >> s[i];       a.insert(s[i]);     }     a.build();     a.query(t);     memcpy(cnt2, cnt, sizeof cnt);     memset(cnt, 0, sizeof cnt);     b.init();     for (int i = 1; i <= n; ++i) {       reverse(s[i].begin(), s[i].end());       b.insert(s[i]);     }     b.build();     reverse(t.begin(), t.end());     b.query(t);     long long ans = 0;     for (int i = 0; i < t.size() - 1; ++i) {       ans += 1ll * cnt2[i] * cnt[t.size() - i - 2];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b;   int main() {     cin >> a >> b;     if (a > b + 1 or (a + 1) * 2 < b) {       cout << -1;       return 0;     }     string s;     s.push_back( 1 );     int n = a + b, ok = 1;     for (int i = 1; i < n; i++) {       if (ok and b > a) {         s.push_back( 1 );         ok = 0;         b--;       } else {         if (s[i - 1] ==  0 ) {           ok = 1;           s.push_back( 1 );           b--;         } else {           s.push_back( 0 );           a--;         }       }     }     if (a == 1) s.pop_back(), s =  0  + s;     cout << s;   }
#include <iostream>   #include <iomanip>   #include <cstdio>   #include <cstdlib>   #include <algorithm>   #include <cmath>   #include <vector>   #include <set>   #include <map>   #include <unordered_set>   #include <unordered_map>   #include <queue>   #include <ctime>   #include <cassert>   #include <complex>   #include <string>   #include <cstring>   #include <chrono>   #include <random>   #include <bitset>      using namespace std;   #define ll long long   #define pi pair<int,int>   #define pll pair<ll,ll>   #define ld  long double        const int INF = 1e9 + 7;   long long MOD;            const int N = 405;      long long dp[N][N];   long long ncr[N][N];   long long p2[N];      void solve(){       int n;       cin >> n >> MOD;       /*           Trivial observation : If the number of segments of `x` is k and the sizes are x_1 , x_2 , ... , x_k.            Then, the number of ways is X! / (x_1! x_2!... x_k!) 2^(x_1 - 1) 2^(x_2 - 1) ..        */              p2[0] = 1LL;       for(int i = 1; i < N; i++){           p2[i] = p2[i - 1] * 2LL % MOD;        }       ncr[1][0] = ncr[1][1] = 1;          for(int i = 2; i < N; i++){           for(int r = 0; r <= i; r++){               if(r == 0 || r == i) ncr[i][r] = 1;               else ncr[i][r] = (ncr[i - 1][r] + ncr[i - 1][r - 1]) % MOD;           }       }              dp[1][1] = 1;          for(int i = 2; i <= n; i++){           for(int manual = 0; manual <= i; manual++){               for(int last = 1; last <= min(manual , i); last++){                   if(i - last - 1 >= 0){                       dp[i][manual] += dp[i - last - 1][manual - last] * ncr[manual][last] % MOD * p2[last - 1] % MOD;                       dp[i][manual] %= MOD;                   } else{                       assert(i == last);                       dp[i][manual] = p2[i - 1];                   }               }           }       }          long long ans = 0;       for(int manual = 1; manual <= n; manual++){           ans += dp[n][manual]; ans %= MOD;       }       cout << ans << endl;   }      int main(){       ios :: sync_with_stdio(false);        cin.tie(nullptr);        cout.tie(nullptr);       int tt = 1;       #ifdef SIEVE       construct();       #endif       for(int tc = 1; tc <= tt; tc++){           // cout <<  Case #  << tc <<  :  ;           solve();       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a = 100, c = 20, d = 10, e = 5;     long long int note, n, rem;     while (scanf( %lld , &n) != EOF) {       note = n / a;       rem = n % a;       note = note + (rem / c);       rem = rem % c;       note = note + (rem / d);       rem = rem % d;       note = note + (rem / e) + (rem % e);       cout << note << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000009;   const int Max = 1000007;   const double PI = acos(-1.0);   long long nc2(long long n) { return (n * (n - 1)) / 2; }   map<long long, long long> mp1, mp2;   map<pair<long long, long long>, long long> mp3;   int main() {     long long i, j, k, l, temp, t, n, m, caseno = 0, ans;     string str;     while (cin >> n) {       mp1.clear();       mp2.clear();       mp3.clear();       for (i = 0; i < n; i++) {         cin >> j >> k;         if (mp1.find(j) == mp1.end()) mp1[j] = 0;         if (mp2.find(k) == mp2.end()) mp2[k] = 0;         mp1[j]++;         mp2[k]++;         pair<long long, long long> ttmp = make_pair(j, k);         if (mp3.find(ttmp) == mp3.end()) mp3[ttmp] = 0;         mp3[ttmp]++;       }       map<long long, long long>::iterator it;       ans = 0;       for (it = mp1.begin(); it != mp1.end(); ++it) {         ans += nc2(it->second);       }       for (it = mp2.begin(); it != mp2.end(); ++it) {         ans += nc2(it->second);       }       map<pair<long long, long long>, long long>::iterator itr;       for (itr = mp3.begin(); itr != mp3.end(); ++itr) {         ans -= nc2(itr->second);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int lis(vector<int>& a) {     if (a.empty()) return 0;     int n = a.size();     int INF = 1000;     vector<int> b(n + 1, INF);     b[0] = -INF;     for (int i = 0; i < n; ++i) {       int val = a[i];       int pos = upper_bound(b.begin(), b.end(), val) - b.begin();       b[pos] = min(b[pos], val);     }     int res = 0;     for (int j = n; j >= 0; --j)       if (b[j] != INF) {         res = j;         break;       }     return res;   }   int brute(int n, int t, vector<int> a) {     for (int i = 0; i < t - 1; ++i)       for (int j = 0; j < n; ++j) a.push_back(a[j]);     int res = lis(a);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n, t;     cin >> n >> t;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     int t0 = 100;     int t1 = 101;     int res = -1;     if (t <= t0) {       res = brute(n, t, a);     } else {       int res0 = brute(n, t0, a);       int res1 = brute(n, t1, a);       res = res1 + (t - t1) * (res1 - res0);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 1;   int n, ans[51], t[51];   long long k, fac[51], dp[51];   bool v[51];   long long mul(long long x, long long y) {     return !x ? 0 : inf / x < y ? inf : x * y;   }   long long cal(int x) { return x < 2 ? 1 : fac[x - 2]; }   void work(int l, int r) {     for (auto i = (l); i <= (r); ++i) t[i] = i, v[i] = 0;     ans[l] = r;     v[r] = 1;     swap(t[l], t[r]);     for (auto i = (l + 1); i <= (r - 1); ++i) {       for (auto j = (l); j <= (r); ++j)         if (!v[j] && i != t[j]) {           if (mul(fac[r - i - 1], dp[n - r]) >= k) {             ans[i] = j;             v[j] = 1;             int x = t[i], y = t[j];             t[x] = y;             t[y] = x;             break;           } else             k -= mul(fac[r - i - 1], dp[n - r]);         }     }     ans[r] = t[r];   }   void sol() {     scanf( %d%lld , &n, &k);     if (dp[n] < k) return (void)printf( -1 n );     int nw = 1;     while (nw <= n)       for (auto i = (1); i <= (n - nw + 1); ++i) {         if (mul(cal(i), dp[n - nw - i + 1]) >= k) {           work(nw, nw + i - 1);           nw += i;           break;         } else           k -= mul(cal(i), dp[n - nw - i + 1]);       }     for (auto i = (1); i <= (n); ++i) printf( %d%c , ans[i], i == n ?   n  :    );   }   int main() {     int t;     fac[0] = 1;     dp[0] = 1;     for (auto i = (1); i <= (50); ++i) fac[i] = mul(fac[i - 1], i);     for (auto i = (1); i <= (50); ++i)       for (auto j = (1); j <= (i); ++j)         dp[i] = min(inf, dp[i] + mul(dp[i - j], cal(j)));     scanf( %d , &t);     for (auto i = (1); i <= (t); ++i) sol();   }
# include <bits/stdc++.h>   # define sz(x) (int)x.size()   # define f first   # define s second      using namespace std;   using ll = long long;      void solve() {     int n, a, b;     cin >> n >> a >> b;     int x, y;     cin >> x >> y;     int c = n - max(a, b) + abs(a - b) / 2;     int d = min(a, b) + abs(a - b) / 2;     if (d >= x && c >= y) cout <<  YES n ;     else cout <<  NO n ;   }       int main(){     ios_base::sync_with_stdio(false);     cin.tie(0);     int t; cin >> t; while (t--)      solve();   }
#include <bits/stdc++.h>   using namespace std;   int a[1010], ans[1010];   int main() {     int n, i, cur = 0, x, y, l1 = 1, l2 = 1;     cin >> n;     for (i = 1; i < n; i++) {       cin >> x >> y;       if (x > y) swap(x, y);       a[x]++;       if (y != n) {         cout <<  NO ;         return 0;       }     }     for (i = 1; i < n; i++) {       cur += a[i];       if (cur > i) {         cout <<  NO ;         return 0;       }     }     cout <<  YES  << endl;     ans[1] = n;     for (i = n - 1; i; i--) {       if (!a[i]) {         while (ans[l2]) l2++;         ans[l2] = i;         continue;       }       l1 += a[i];       ans[l1] = i;     }     for (i = 1; i < n; i++) cout << ans[i] <<     << ans[i + 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)3e5 + 10;   const int inf = (int)1e9 + 5;   const long long llinf = (long long)1e18 + 5;   long long a[maxn];   long long d, i, n, k, l, query, first, second, pruf, pruf2, j, m, p, last, sum,       h, z, r;   int main() {     cin >> n;     for (i = 1; i < n + 1; i++) cin >> a[i];     string x;     for (i = 0; i < n + 1; i++) {       getline(cin, x);       k = 0;       if (i != 0) {         for (int re = 0; re < x.size(); re++) {           if ((x[re] ==  a ) or (x[re] ==  e ) or (x[re] ==  i ) or               (x[re] ==  o ) or (x[re] ==  u ) or (x[re] ==  y ))             k++;         }         if (k != a[i]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:32000000 )   const int nil = -1;   using namespace std;   inline bool read(int& val) { return scanf( %d , &val) != -1; }   inline bool read(long long& val) { return scanf( %I64d , &val) != -1; }   inline bool read(double& val) { return scanf( %lf , &val) != -1; }   inline bool read(char* val) { return scanf( %s , val) != -1; }   template <class T1, class T2>   inline bool read(T1& a, T2& b) {     return read(a) && read(b);   }   template <class T1, class T2, class T3>   inline bool read(T1& a, T2& b, T3& c) {     return read(a) && read(b) && read(c);   }   template <class T1, class T2, class T3, class T4>   inline bool read(T1& a, T2& b, T3& c, T4& d) {     return read(a) && read(b) && read(c) && read(d);   }   template <class T1, class T2, class T3, class T4, class T5>   inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) {     return read(a) && read(b) && read(c) && read(d) && read(e);   }   const int N = 1111111;   const long long mod = 1000000007;   char str[N];   long long cnt[N];   int main() {     read(str);     int n = strlen(str);     cnt[0] = 0;     long long sum = 0;     long long pow2 = 1;     for (int i = 0, _ = (n); i < _; ++i) {       if (str[i] ==  a ) {         pow2 = pow2 * 2 % mod;       } else {         sum = (sum + pow2 - 1) % mod;       }     }     cout << sum % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   const int M = 1e6 + 500;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int BASE = 31337;   const int LOG = 18;   const int OFF = (1 << LOG);   const double EPS = 1e-9;   const double PI = 3.1415926535;   int n, k, bio[2 * M + 10];   vector<int> v;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       v.push_back(x);       bio[x]++;     }     for (int i = 1; i < 2 * M; i++) {       bio[i] += bio[i - 1];     }     int sol = 0;     for (int i = 0; i < v.size(); i++) {       if ((bio[v[i] + k] - bio[v[i]]) == 0) sol++;     }     printf( %d n , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005], f[100005], cnt[100005], ans[100005];   int main() {     int i, j, k, l, n, m;     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> j;       if (!cnt[j]) f[j] = i;       cnt[j]++;     }     int flag = 1;     l = 1;     for (i = 1; i <= m; i++) {       cin >> j;       if (flag)         if (!cnt[j])           flag = 0;         else if (cnt[j] > 1)           flag = 2;         else           ans[l++] = f[j];     }     if (l == m + 1) {       cout <<  Possible n ;       for (i = 1; i <= m; i++) cout << ans[i] <<    ;       cout << endl;     } else if (!flag)       cout <<  Impossible n ;     else       cout <<  Ambiguity n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> e[200010];   struct Node {     int sz, l;   } c[200010];   bool cmp(const Node &p, const Node &q) { return (p.sz - p.l) > (q.sz - q.l); }   void dfs(int x, int fa) {     c[x].l = c[fa].l + 1;     for (int i = 0; i < (int)e[x].size(); i++) {       int y = e[x][i];       if (y == fa) continue;       dfs(y, x);       c[x].sz += c[y].sz;     }     c[x].sz++;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     k = n - k;     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       e[a].push_back(b);       e[b].push_back(a);     }     dfs(1, 0);     sort(c + 1, c + n + 1, cmp);     long long ans = 0;     for (int i = 1; i <= k; i++) {       ans += (c[i].sz - c[i].l);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long n, q;       cin >> n >> q;       while (q--) {         long long x;         cin >> x;         long long c = 1;         for (long long int i = 0; i < 63; i++)           if ((x + c - 2 * n) % (2 * c) == 0) {             cout << ((x + c - 2 * n) / (2 * c)) + n <<   n ;             break;           } else             c *= 2;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 2)       cout <<  -1 ;     else if (n == 3)       cout <<  210 ;     else {       int mod = 1;       for (int i = 1; i < n; ++i) mod = (mod * 10) % 210;       if (n > 3) cout <<  1 ;       for (int i = 0; i < n - 4; ++i) cout <<  0 ;       if (210 - mod < 100) cout <<  0 ;       cout << 210 - mod;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const int d[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};   char a[N][N];   int v[4][N][N][2], m, n;   int q[N * N * 4 * 2][4];   int check(int x, int y) {     if (x >= 1 && x <= m && y >= 1 && y <= n && a[x][y] ==  B )       return 1;     else       return 0;   }   int bfs(int sx, int sy) {     int l = 1, r = 0, i, j, x, y, k, t, nx, ny, nk;     memset(v, 0, sizeof(v));     for (i = 0; i < 4; i++) {       v[i][sx][sy][0] = 1;       r++;       q[r][0] = i;       q[r][1] = sx;       q[r][2] = sy;       q[r][3] = 0;     }     while (l <= r) {       x = q[l][1];       y = q[l][2];       k = q[l][0];       t = q[l][3];       l++;       nx = x + d[k][0];       ny = y + d[k][1];       if (check(nx, ny))         if (!v[k][nx][ny][t]) {           v[k][nx][ny][t] = 1;           r++;           q[r][0] = k;           q[r][1] = nx;           q[r][2] = ny;           q[r][3] = t;         }       if (t == 0) {         for (i = -1; i <= 1; i += 2) {           nk = (k + 4 + i) % 4;           if (!v[nk][x][y][1]) {             v[nk][x][y][1] = 1;             r++;             q[r][0] = nk;             q[r][1] = x;             q[r][2] = y;             q[r][3] = 1;           }         }       }     }     for (i = 1; i <= m; i++)       for (j = 1; j <= n; j++)         if (a[i][j] ==  B ) {           int f = 0;           for (k = 0; k < 4; k++)             for (t = 0; t <= 1; t++)               if (v[k][i][j][t]) f = 1;           if (f == 0) return 0;         }     return 1;   }   int main() {     int i, j;     scanf( %d%d , &m, &n);     for (i = 1; i <= m; i++) scanf( %s , a[i] + 1);     for (i = 1; i <= m; i++)       for (j = 1; j <= n; j++)         if (a[i][j] ==  B ) {           if (bfs(i, j) == 0) {             printf( NO n );             return 0;           }         }     printf( YES n );   }
#include <bits/stdc++.h>   using namespace std;   long long int d[(100010)];   const long long int mod = 1e9 + 7;   int main() {     int n, m;     cin >> n >> m;     d[0] = d[1] = 1;     int k = max(n, m);     for (int i = 2; i <= k; i++) {       d[i] = (d[i - 1] + d[i - 2]) % mod;     }     long long int ans = (d[n] + d[m] - 1) % mod;     ans = (ans * 2) % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:256000000 )   FILE *stream;   const int INF = 1e9 + 7;   const long long INFL = (long long)1e18 + 1;   const int SIZE = 2e5 + 10;   const int TSIZE = 1e3 + 10;   const long double eps = 0.000001;   const long long MOD = 1e9 + 7;   char POW(char a, char b) {     if (b == 0) return 1;     char cur = POW(a, b / 2);     if (b % 2 == 0)       return cur * cur;     else       return cur * cur * a;   }   long long gcd(long long &x, long long &y, long long a, long long b) {     if (a == 0) {       y = 1;       x = 0;       return abs(b);     }     long long x1 = 0, y1 = 0;     long long d = gcd(x1, y1, b % a, a);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long gcd(long long a, long long b) {     if (a == 0) {       return abs(b);     }     long long d = gcd(b % a, a);     return d;   }   void accept() {     int n, k, j = 2;     cin >> n >> k;     vector<int> ans;     while (n > 1 && ans.size() < k) {       while (n % j == 0 && ans.size() < k - 1) {         n /= j;         ans.push_back(j);       }       if (n > 1 && ans.size() == k - 1) {         ans.push_back(n);         break;       }       j++;     }     if (ans.size() == k) {       for (int i = 0; i < k; i++) {         cout << ans[i] <<    ;       }     } else {       cout << -1;     }   }   void solution() {     long long t = 1;     for (long long i = 0; i < t; i++) {       accept();     }     return;   }   void test() {     cout <<  100000 n ;     for (int k = 0; k < 100000 - 1; k++) {       cout << k + 1 <<    ;     }     cout <<  100000 n ;   }   int main() {     srand(time(0));     solution();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pow_mod(long long int a, long long int b) {     long long int res = 1;     while (b != 0) {       if (b & 1) {         res = (res * a) % 1000000007;       }       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   void solve() {     long long int n, m, k;     cin >> n >> m >> k;     long long int a[n + 1][m];     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) cin >> a[i][j];     }     for (long long int j = 0; j < m; j++) a[n][j] = 0;     long long int dp[n + 1][m];     memset(dp, 0, sizeof(dp));     long long int sum[n + 1][m], mx_p[n + 1][m], mx_s[n + 1][m];     memset(sum, 0, sizeof(sum));     memset(mx_s, 0, sizeof(mx_s));     memset(mx_p, 0, sizeof(mx_p));     for (long long int i = 0; i <= n; i++) {       for (long long int j = 0; j < m; j++) {         if (j == 0)           sum[i][j] = a[i][j];         else           sum[i][j] = a[i][j] + sum[i][j - 1];       }     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 0; j < m; j++) {         if (j - k + 1 >= 0) {           if (i == 0) {             dp[i][j] = sum[i][j] - (j - k >= 0 ? sum[i][j - k] : 0LL);           } else {             dp[i][j] = sum[i][j] - (j - k >= 0 ? sum[i][j - k] : 0LL);             dp[i][j] += sum[i - 1][j] - (j - k >= 0 ? sum[i - 1][j - k] : 0LL);             if (i != 1) {               long long int res = 0;               if (j + k < m) res = mx_s[i - 1][j + k];               if (j - k >= 0) res = max(res, mx_p[i - 1][j - k]);               for (long long int xx = j; xx > max(-1LL, j - k); xx--)                 res = max(res, dp[i - 1][xx] - sum[i - 1][xx] +                                    (j - k >= 0 ? sum[i - 1][j - k] : 0LL));               for (long long int xx = j + 1; xx < min(m, j + k); xx++)                 res = max(res, dp[i - 1][xx] - sum[i - 1][j] +                                    (xx - k >= 0 ? sum[i - 1][xx - k] : 0LL));               dp[i][j] += res;             }           }           mx_p[i][j] = dp[i][j];           if (j - 1 >= 0) mx_p[i][j] = max(mx_p[i][j], mx_p[i][j - 1]);         }       }       for (long long int j = m - 1; j >= 0; j--) {         if (j == m - 1)           mx_s[i][j] = dp[i][j];         else           mx_s[i][j] = max(mx_s[i][j + 1], dp[i][j]);       }     }     long long int ans = 0;     for (long long int j = 0; j < m; j++) {       ans = max(ans, dp[n][j]);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T = 1;     cin >> T;     while (T--) {       string s;       int x;       cin >> s >> x;       string ans;       int n = s.size();       for (int i = 0; i < n; i++) ans.push_back( 1 );       for (int i = 0; i < n; i++) {         if (s[i] ==  0 ) {           if (i - x >= 0) ans[i - x] =  0 ;           if (i + x < n) ans[i + x] =  0 ;         }       }       bool f = 1;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) {           bool t = 0;           if (i + x < n && ans[i + x] ==  1 ) t = 1;           if (i - x >= 0 && ans[i - x] ==  1 ) t = 1;           if (!t) f = 0;         }       }       if (f)         cout << ans << endl;       else         cout <<  -1 n ;     }     return 0;   }