malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   int dp[303030][30];   int u, v;   int in[303030];   vector<int> adj[303030];   char s[303030];   int main() {     scanf( %d %d , &n, &m);     scanf( %s , s);     for (int i = 0; i < m; ++i) {       scanf( %d %d , &u, &v);       --u;       --v;       adj[u].push_back(v);       in[v]++;     }     queue<int> q;     for (int i = 0; i < n; ++i) {       if (in[i] == 0) {         q.push(i);       }     }     int cnt = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       ++cnt;       dp[u][s[u] -  a ]++;       for (int v : adj[u]) {         if (--in[v] == 0) {           q.push(v);         }         for (int i = 0; i < 26; ++i) {           dp[v][i] = max(dp[v][i], dp[u][i]);         }       }     }     if (cnt == n) {       int ans = 0;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < 26; ++j) {           ans = max(ans, dp[i][j]);         }       }       printf( %d n , ans);     } else {       printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int N = 3e6 + 5;   int a[55][55], b[55][55], aa[55][55], bb[55][55];   int row(int x, int y) {     for (int i = 1; i <= x; i++) {       int k = 1;       for (int j = 2; j <= y; j++) {         if (a[i][j] > a[i][k]) {           k = j;         } else           return 0;       }     }     for (int i = 1; i <= x; i++) {       int k = 1;       for (int j = 2; j <= y; j++) {         if (b[i][j] > b[i][k]) {           k = j;         } else           return 0;       }     }     return 1;   }   int col(int x, int y) {     for (int i = 1; i <= y; i++) {       int k = 1;       for (int j = 2; j <= x; j++) {         if (a[j][i] > a[k][i]) {           k = j;         } else           return 0;       }     }     for (int i = 1; i <= y; i++) {       int k = 1;       for (int j = 2; j <= x; j++) {         if (b[j][i] > b[k][i]) {           k = j;         } else           return 0;       }     }     return 1;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> aa[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> bb[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         a[i][j] = min(aa[i][j], bb[i][j]);         b[i][j] = max(aa[i][j], bb[i][j]);       }     }     if (row(n, m) && col(n, m))       cout <<  Possible ;     else       cout <<  Impossible ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<long long> dd;   long long su;   long long revsum[100001];   struct tab {     long long l;     long long d;   } arr[100001];   long long findsumoftop(long long k) {     long long ans = 0;     multiset<long long>::iterator it = dd.begin();     while (k--) {       if (it == dd.end()) {         break;       } else {         ans += *it;         it++;       }     }     return -ans;   }   bool compare(const tab& t1, const tab& t2) { return t1.l < t2.l; }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; ++i) cin >> arr[i].l;     for (long long i = 0; i < n; ++i) cin >> arr[i].d;     sort(arr, arr + n, compare);     for (long long i = n - 1; i >= 0; --i) revsum[i] = arr[i].d + revsum[i + 1];     long long st = 0;     long long en = 1;     long long ma = 300000000;     while (st < n) {       if (arr[st].l == arr[en].l)         en++;       else {         long long matmp = (su - findsumoftop(en - st - 1) + revsum[en]);         for (long long i = st; i < en; ++i) dd.insert(-arr[i].d), su += arr[i].d;         ma = min(ma, matmp);         st = en;         en++;       }     }     cout << ma << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 550005;   const long long mod = 998244353;   int n, u, v;   vector<int> g[N];   long long dp[N][2][2];   inline long long bin(long long x, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = res * x % mod;       x = x * x % mod;       k >>= 1;     }     return res;   }   vector<long long> pre, su;   inline void dfs(int v, int p = 0) {     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (to == p) {         swap(g[v][i], g[v].back());         g[v].pop_back();         break;       }     }     for (int to : g[v]) {       dfs(to, v);     }     int sz = g[v].size();     pre.resize(sz, 0);     su.resize(sz, 0);     for (int i = 0; i < sz; ++i) {       int to = g[v][i];       pre[i] = (dp[to][1][0] + dp[to][0][0]) % mod;       if (i) pre[i] = pre[i - 1] * pre[i] % mod;     }     for (int i = sz - 1; i >= 0; --i) {       int to = g[v][i];       su[i] = (dp[to][0][0] + dp[to][1][0]) % mod;       if (i + 1 < sz) su[i] = su[i] * su[i + 1] % mod;     }     long long s = 1;     for (int to : g[v]) {       s = s * dp[to][1][0] % mod;     }     dp[v][0][0] = 0;     dp[v][0][1] = 1;     dp[v][1][0] = s;     dp[v][1][1] = 0;     for (int i = 0; i < sz; ++i) {       int to = g[v][i];       long long add = dp[to][0][1];       if (i - 1 >= 0) add = add * pre[i - 1] % mod;       if (i + 1 < sz) add = add * su[i + 1] % mod;       dp[v][0][0] += add;       dp[v][0][0] %= mod;     }     (dp[v][1][0] += dp[v][0][0]) %= mod;     for (int to : g[v]) {       dp[v][0][1] = dp[v][0][1] * (dp[to][1][0] + dp[to][0][0]) % mod;     }   }   vector<int> e[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n - 1; ++i) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int x = min(n, 3);     dfs(x);     cout << dp[x][1][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long n;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       if (n < 6) {         cout << 15 << endl;       } else if (n % 2 == 0) {         cout << n / 2 * 5 << endl;       } else {         n++;         cout << n / 2 * 5 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     string a[n];     a[0] = s;     for (int i = 1; i < n; i++) {       a[i] = a[i - 1][n - 1] + a[i - 1].substr(0, n - 1);     }     int dem = 0;     for (int i = 0; i < n; i++) {       if (a[i] !=  . ) {         dem++;         for (int j = i + 1; j < n; j++) {           if (a[j] == a[i]) {             a[j] =  . ;           }         }       }     }     cout << dem;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 1e4 + 5;   int n, k;   int a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn];   int main() {     scanf( %d%d , &n, &k);     memset(dp1, -0x3f, sizeof(dp1));     memset(dp2, -0x3f, sizeof(dp2));     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= n; i++) {       c[i] = b[i] * k - a[i];     }     dp1[0] = dp2[0] = 0;     for (int i = 1; i <= n; i++) {       if (c[i] >= 0) {         for (int v = 10000; v >= c[i]; v--)           dp1[v] = max(dp1[v], dp1[v - c[i]] + a[i]);       } else {         for (int v = 10000; v >= -c[i]; v--)           dp2[v] = max(dp2[v], dp2[v + c[i]] + a[i]);       }     }     int ans = 0;     for (int i = 0; i <= 10000; i++) ans = max(ans, dp1[i] + dp2[i]);     if (ans)       printf( %d n , ans);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res % mod;   }   const int N = 5e3 + 10;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int k;     cin >> k;     cout <<  2000 n ;     for (int i = 1; i <= 1998; ++i) cout <<  0  ;     int d = 1999 - k % 1999;     int x = (k + d) / 1999;     cout << -d <<     << x + d << endl;     return 0;   }
#include <bits/stdc++.h>   int dis[1048576];   std::vector<int> node[1048576], rnode[1048576];   int main() {     int n, m, s, t;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       node[u].push_back(v);       rnode[v].push_back(u);     }     scanf( %d%d , &s, &t);     memset(dis + 1, (int)0x7f7f7f7f, sizeof(int) * n);     dis[t] = 0;     std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >,                         std::greater<std::pair<int, int> > >         pq;     pq.push(std::pair<int, int>(0, t));     while (!pq.empty()) {       const int u = pq.top().second, cu = pq.top().first;       pq.pop();       if (cu != dis[u]) continue;       for (auto v : rnode[u]) {         if (dis[v] <= dis[u]) continue;         int max = 0, min = dis[v];         for (auto k : node[v]) {           max = std::max(max, dis[k]);           min = std::min(min, dis[k]);         }         const int cv = std::min(max, min + 1);         if (cv < dis[v]) pq.push(std::pair<int, int>(dis[v] = cv, v));       }     }     printf( %d n , dis[s] == (int)0x7f7f7f7f ? -1 : dis[s]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const long long p = 1e9 + 7;   long long dp[N], dp1[N];   long long modexp(long long a, long long b, long long p) {     long long ans = 1LL;     a %= p;     while (b) {       if (b & 1) ans = ans * a % p;       b >>= 1;       a = a * a % p;     }     return ans;   }   int main() {     memset(dp, 0, sizeof(dp));     int n, k;     scanf( %d%d , &n, &k);     dp[0] = 1LL;     for (int i = 1; i <= k; i++) {       for (int j = 0; j < N; j++) {         if (j) {           dp1[j] += j * 1LL * dp[j];           dp1[j] %= p;         }         if (dp[j]) {           dp1[j + 1] += (n - j) * 1LL * dp[j];           dp1[j + 1] %= p;         }       }       for (int j = 0; j < N; j++) dp[j] = dp1[j];       memset(dp1, 0, sizeof(dp1));     }     long long ans = 0;     for (int i = 0; i <= min(n, N - 1); i++)       ans = (ans + dp[i] * modexp(2, n - i, p) % p) % p;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int C = 20, A = 40;   int n, liq;   int dp[1 << C];   long long k[A];   int main() {     scanf(  %d %d , &n, &liq);     for (int i = 0; i < n; i++)       for (int j = 0, first; j < n; j++)         cin >> first, k[i] |= (long long)(first || i == j) << j;     for (int i = 1; i < (1 << max(0, n - C)); i++) {       int first = i;       for (int j = 0; j < C; j++)         if ((i >> j) & 1) first &= k[j + C] >> C;       if (first == i) dp[i] = __builtin_popcount(i);     }     for (int i = 1; i < (1 << max(0, n - C)); i++)       for (int j = 0; j < C; j++)         if ((i >> j) & 1) dp[i] = max(dp[i], dp[i ^ (1 << j)]);     int ans = 0;     for (int i = 0; i < (1 << min(C, n)); i++) {       int first = i, second = (1 << max(0, n - C)) - 1;       for (int j = 0; j < min(C, n); j++)         if ((i >> j) & 1) first &= k[j] & ((1 << C) - 1), second &= k[j] >> C;       if (first != i) continue;       ans = max(ans, __builtin_popcount(i) + dp[second]);     }     long double l = liq, a = ans;     cout << fixed << setprecision(7) << (l * l * (a - 1)) / 2 / a << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int64_t> A(8, 8);     vector<int64_t> A_high(8, 0);     vector<int64_t> B(8, 8);     vector<int64_t> B_high(8, 8);     int64_t amax = 8;     int64_t bmax = 8;     char k;     for (int64_t i = 0; i < 8; i++) {       for (int64_t j = 0; j < 8; j++) {         cin >> k;         if (k ==  B ) {           if (B_high[j] > i) {             B_high[j] = i;           }           B[j] = 7 - i;         } else if (k ==  W ) {           A_high[j] = i;           if (A[j] > i) {             A[j] = i;           }         }       }     }     for (int64_t i = 0; i < 8; i++) {       if (amax > A[i] && (B_high[i] > A[i])) {         amax = A[i];       }       if (bmax > B[i] && (A_high[i] < 7 - B[i])) {         bmax = B[i];       }     }     if (amax <= bmax) {       cout <<  A  << endl;     } else {       cout <<  B  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<string, int> mp;     int n, m;     cin >> n >> m;     int same = 0;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       mp[s] = 1;     }     for (int i = 0; i < m; i++) {       string s;       cin >> s;       if (mp[s]) same++;     }     n = n - same;     m = m - same;     if (same % 2 == 1)       n >= m ? cout <<  YES  : cout <<  NO ;     else       n > m ? cout <<  YES  : cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long fpow(long long b, long long x) {     long long res = 1;     while (x) {       if (x & 1) res = (res * b) % MOD;       b = (b * b) % MOD;       x >>= 1;     }     return res;   }   long long c(long long k, long long r) {     if (r < 0) return 0;     if (r == 0) return 1;     return c(k, r - 1) * (k - r + 1) % MOD * fpow(r, MOD - 2) % MOD;   }   int main() {     long long n, m, g;     cin >> n >> m >> g;     if (m == 1) {       if (n & 1) {         if (g)           cout << (n - 1) / 2 << endl;         else           cout << (n - 1) / 2 + 2 << endl;       } else {         if (g)           cout << n / 2 + 1 << endl;         else           cout << n / 2 << endl;       }       return 0;     }     if (m == 0) {       if (g == !(n & 1))         printf( 1 n );       else         printf( 0 n );       return 0;     }     if (n == 0) {       if (g)         printf( 0 n );       else         printf( 1 n );       return 0;     }     long long k = 1 + g;     long long C = c(n + m - k, m - 1);     long long ans = C;     for (k = k + 2; k <= n + 1; k += 2) {       C = C * (n - k + 2) % MOD * (n - k + 3) % MOD *           fpow(n + m - k + 2, MOD - 2) % MOD * fpow(n + m - k + 1, MOD - 2) % MOD;       ans = (ans + C) % MOD;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> vec_splitter(string s) {     for (char& c : s) c = c ==  ,  ?     : c;     stringstream ss;     ss << s;     vector<string> res;     for (string z; ss >> z; res.push_back(z))       ;     return res;   }   void debug_out(vector<string> args, int idx) { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, Head H, Tail... T) {     if (idx > 0) cerr <<  ,  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, T...);   }   void localTest() {}   const long long N = 2e5 + 5, MOD = 998244353;   long long A[N], fac[N], ifac[N];   long long power(long long a, long long b, long long c) {     long long ret = 1;     while (b) {       if (b & 1) {         ret = (ret * a) % c;       }       b >>= 1;       a = (a * a) % c;     }     return ret;   }   long long C(long long n, long long r) {     if (n < r) {       return 0;     }     long long ret = fac[n];     ret = (ret * ifac[r]) % MOD;     ret = (ret * ifac[n - r]) % MOD;     return ret;   }   int main() {     localTest();     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     fac[0] = ifac[0] = 1;     for (long long i = 1; i < N; ++i) {       fac[i] = (i * fac[i - 1]) % MOD;       ifac[i] = power(fac[i], MOD - 2, MOD);     }     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= n; ++i) {       cin >> A[i];     }     if (k == 1) {       cout <<  0 n ;       return 0;     }     long long ans = power(k, n, MOD), val = 0, fixed = 0, move = n, sum = 0;     for (long long i = 1; i <= n; ++i) {       if (A[i] == A[i % n + 1]) {         fixed++;         move--;       }     }     val = power(k, fixed, MOD);     for (long long i = 0; i <= move / 2; ++i) {       long long mul = C(move, i) * C(move - i, i) % MOD;       mul = (mul * power(k - 2, move - 2 * i, MOD)) % MOD;       sum += mul;       sum %= MOD;     }     val = (val * sum) % MOD;     ans = (ans - val + MOD) % MOD;     ans = (ans * power(2, MOD - 2, MOD)) % MOD;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,unroll-loops )   const long long int MAXN = 4e3 + 20, md = 1e9 + 7, inf = 5e18;   int dp[MAXN][100][100], a[MAXN], ps[MAXN], sp[MAXN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -63, sizeof(dp));     long long int n, sq;     cin >> n >> a[0];     ps[0] = a[0];     sq = ceil(sqrt(2 * n));     for (int i = 1; i < n; i++) {       cin >> a[i];       ps[i] = ps[i - 1] + a[i];     }     sp[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; i--) {       sp[i] = sp[i + 1] + a[i];     }     if (n == 1) {       cout << a[0] <<   n ;       return 0;     }     if (n == 2) {       cout << a[0] + abs(a[1]) <<   n ;       return 0;     }     if (n == 3) {       int h = a[0] + a[1], q;       q = -a[2] - abs(a[1]);       cout << max(h, q + a[0]) <<   n ;       return 0;     }     for (int i = n / 2 - 1; i >= 0; i--) {       for (int k = 1; k <= sq; k++) {         for (int j = 0; j <= k; j++) {           int l = i, r = n - l - j - 1, h1, h2;           if (r <= l) break;           l += k;           r -= k;           if (r <= l) {             r += k;             if (l < r) {               h1 = ps[l] - sp[r];             } else {               l -= k;               dp[i][k][j] = ps[l] - sp[r];               continue;             }           } else {             h1 = dp[l][k][j];             r--;             if (l < r) {               h1 = min(h1, dp[l][k + 1][j + 1]);             }           }           l = i;           r = n - l - j - 1;           l += k + 1;           r -= k + 1;           if (r <= l) {             r += k + 1;             if (l < r) {               h2 = ps[l] - sp[r];             } else {               dp[i][k][j] = h1;               continue;             }           } else {             h2 = dp[l][k + 1][j];             r--;             if (l < r) {               h2 = min(h2, dp[l][k + 2][j + 1]);             }           }           dp[i][k][j] = max(h1, h2);         }       }     }     int h1 = min(dp[1][2][0], (dp[1][3][1] < -1e6 ? 500000000 : dp[1][3][1])),         h2 = min(dp[0][1][0], dp[0][2][1]);     cout << max(h1, h2) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-11;   pair<int, int> c1, c2, r1, r2;   int ans = 0;   long double dst(pair<int, int> a, pair<int, int> b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   int main() {     cout << setiosflags(ios::fixed) << setprecision(10);     cin >> c1.first >> c1.second >> r1.first >> r1.second;     cin >> c2.first >> c2.second >> r2.first >> r2.second;     long double D = dst(c1, c2);     if (D > r1.first * r1.first) {       if ((sqrt(D) >= r1.first + r2.second) || (sqrt(D) + r1.first <= r2.first))         ans++;     } else {       if ((sqrt(D) + r2.second <= r1.first) || (sqrt(D) + r1.first <= r2.first))         ans++;     }     if (D > r2.first * r2.first) {       if ((sqrt(D) >= r2.first + r1.second) || (sqrt(D) + r2.first <= r1.first))         ans++;     } else {       if ((sqrt(D) + r1.second <= r2.first) || (sqrt(D) + r2.first <= r1.first))         ans++;     }     if (D > r1.second * r1.second) {       if ((sqrt(D) >= r1.second + r2.second) || (sqrt(D) + r1.second <= r2.first))         ans++;     } else {       if ((sqrt(D) + r2.second <= r1.second) || (sqrt(D) + r1.second <= r2.first))         ans++;     }     if (D > r2.second * r2.second) {       if ((sqrt(D) >= r2.second + r1.second) || (sqrt(D) + r2.second <= r1.first))         ans++;     } else {       if ((sqrt(D) + r1.second <= r2.second) || (sqrt(D) + r2.second <= r1.first))         ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500010;   int n, m;   char a[maxn], b[maxn];   char s[maxn * 2], c[maxn * 3];   int z[maxn * 3];   int lcp[maxn];   int lcs[maxn];   void z_init(int len) {     int l = 1, r = 1;     z[1] = len;     for (int i = 2; i <= len; i++) {       if (i > r) {         l = i;         r = i;         while (r <= len && c[r - i + 1] == c[r]) r++;         z[i] = r - l;         r--;       } else {         int k = i - l + 1;         if (z[k] < r - i + 1)           z[i] = z[k];         else {           l = i;           while (r <= len && c[r - i + 1] == c[r]) r++;           z[i] = r - l;           r--;         }       }     }   }   void init() {     for (int i = 1; i <= m; i++) c[i] = s[i];     c[m + 1] =  # ;     for (int i = 1; i <= n; i++) c[m + 1 + i] = a[i];     c[n + m + 2] =   0 ;     z_init(n + m + 1);     for (int i = 1; i <= n; i++) lcp[i] = z[m + 1 + i];     for (int i = 1; i <= m; i++) c[i] = s[m + 1 - i];     c[m + 1] =  # ;     for (int i = 1; i <= n; i++) c[m + 1 + i] = b[n + 1 - i];     c[n + m + 2] =   0 ;     z_init(n + m + 1);     for (int i = 1; i <= n; i++) lcs[i] = z[m + 1 + n + 1 - i];   }   long long cnt[maxn * 2], sum[maxn * 2];   int lowbit(int x) { return x & (-x); }   void add(int v) {     int x = v;     while (x <= n) sum[x] += v, cnt[x]++, x += lowbit(x);   }   void sub(int v) {     int x = v;     while (x <= n) sum[x] -= v, cnt[x]--, x += lowbit(x);   }   long long get_sum(int x) {     long long res = 0;     while (x) res += sum[x], x -= lowbit(x);     return res;   }   long long get_cnt(int x) {     long long res = 0;     while (x) res += cnt[x], x -= lowbit(x);     return res;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %s%s%s , a + 1, b + 1, s + 1);     init();     long long ans = 0;     for (int i = 1; i <= min(n, m - 1); i++) add(max(1, m - lcs[i]));     for (int i = 1, r; i <= n; i++) {       r = min(m - 1, lcp[i]);       ans += 1LL * (r + 1) * get_cnt(r) - get_sum(r);       sub(max(1, m - lcs[i]));       if (i + m - 1 <= n) add(max(1, m - lcs[i + m - 1]));     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     int n, k;     string s;     while (t--) {       cin >> n >> k >> s;       vector<int> A(n + 1);       for (int i = 0; i < (int)(n); i++) {         if (s[i] ==  1 ) {           A[max(0, i - k)]++;           A[min(n - 1, i + k) + 1]--;         }       }       for (int i = 0; i < (int)(n + 1); i++) {         if (i > 0) A[i] += A[i - 1];       }       int cnt = 0;       int i = 0;       while (i < n) {         if (A[i] == 0) {           cnt++;           i += k + 1;         } else           i++;       }       cout << cnt << endl;     }     return 0;   }