malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m, s, t, k, a, b, x, y, u;   const int mod = 1e9 + 7;   const int mxn = 2e5 + 5;   long long mn = 1e18, mx = 0;   long long arr[2000000], wan[2000000], finl[2000000];   string str, str2;   vector<vector<long long> > v(200000), cm(200000);   map<long long, long long> mp, pm;   map<pair<long long, long long>, long long> frq;   int main() {     ios_base::sync_with_stdio(0);     t = 1;     while (t--) {       cin >> n;       long long z;       for (int i = 0; i < n - 2; i++) {         cin >> x >> y >> z;         mp[x]++;         mp[y]++;         mp[z]++;         frq[{x, y}]++, frq[{y, x}]++;         if (frq[{x, y}] == 2) cm[x].push_back(y), cm[y].push_back(x);         frq[{x, z}]++, frq[{z, x}]++;         if (frq[{x, z}] == 2) cm[x].push_back(z), cm[z].push_back(x);         frq[{z, y}]++, frq[{y, z}]++;         if (frq[{z, y}] == 2) cm[z].push_back(y), cm[y].push_back(z);       }       for (int i = 1; i <= n; i++) {         if (mp[i]) {           v[mp[i]].push_back(i);         }       }       int l = 0;       for (int i = 1; i <= 2; i++) {         long long fr = 0, se = 0;         long long valf = 0, vals = 0;         int j = 0;         for (auto it : v[i]) {           if (i == 1) {             arr[l++] = it;             pm[it]++;             break;           } else {             if (!j)               fr = frq[{arr[l - 1], it}], valf = it;             else               se = frq[{arr[l - 1], it}], vals = it;             j++;           }         }         if (i != 1) {           if (fr > se) {             arr[l++] = valf;             pm[valf]++;           } else             arr[l++] = vals, pm[vals]++;           ;         }       }       for (int i = 0; i < l; i++) cout << arr[i] <<    ;       long long cn = n - 4;       while (cn) {         for (auto i : cm[arr[l - 1]]) {           if (!pm[i]) {             pm[i] = 1;             cout << i <<    ;             arr[l++] = i;           }         }         cn--;       }       for (int i = 2; i >= 1; i--) {         for (auto it : v[i]) {           if (!pm[it]) {             cout << it <<    ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100;   const int MAXLEN = 26;   bool done[26];   bool have[26];   bool before[26][26];   char nxt[26];   int n;   char s[MAXLEN + 1];   void run() {     memset(done, false, sizeof(done));     memset(have, false, sizeof(have));     memset(before, false, sizeof(before));     memset(nxt,  ? , sizeof(nxt));     scanf( %d , &n);     for (int i = (0); i < (n); ++i) {       scanf( %s , s);       int slen = strlen(s);       for (int j = (0); j < (slen); ++j) have[s[j] -  a ] = true;       for (int j = (0); j < (slen); ++j)         for (int k = (j + 1); k < (slen); ++k)           before[s[j] -  a ][s[k] -  a ] = true;       for (int j = (0); j < (slen - 1); ++j) nxt[s[j] -  a ] = s[j + 1];     }     for (int k = (0); k < (26); ++k)       for (int i = (0); i < (26); ++i)         for (int j = (0); j < (26); ++j)           if (before[i][k] && before[k][j]) before[i][j] = true;     while (true) {       int idx = -1;       for (int i = (0); i < (26); ++i)         if (!done[i] && have[i]) {           bool ok = true;           for (int j = (0); j < (26); ++j)             if (!done[j] && have[j] && before[j][i]) ok = false;           if (ok) {             idx = i;             break;           }         }       if (idx == -1) {         puts(  );         break;       }       while (true) {         printf( %c ,  a  + idx);         done[idx] = true;         if (nxt[idx] ==  ? )           break;         else           idx = nxt[idx] -  a ;       }     }   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[120], b[120];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       for (long long i = 0; i < n; i++) cout << a[i] <<    ;       cout <<   n ;       for (long long i = 0; i < n; i++) cout << b[i] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1111][1111];   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < n - 1; j++) a[i][j] = 1 + (i + j) % (n - 1);     for (int i = 0; i < n - 1; i++)       a[n - 1][i] = a[i][n - 1] = a[i][i], a[i][i] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) printf( %d  , a[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long y, k, n;     cin >> y >> k >> n;     int flag = 0;     int i = y / k + 1;     while (i * k <= n) {       cout << i * k - y <<    ;       i++;       flag++;     }     if (!flag) cout <<  -1 ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, a[N];   long long s[2][N];   double Ans;   void Add(int tp, int x, long long sum) {     while (x <= n) s[tp][x] += sum, x += (x & (-x));   }   long long Query(int tp, int x) {     long long ret = 0;     while (x) ret += s[tp][x], x -= (x & (-x));     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       Ans += 1.0 * Query(0, n - a[i] + 1) / (1.0 * n * (n + 1)) * i;       Ans += 1.0 * i * (n - i + 1) * (n - i) / (2.0 * n * (n + 1));       Add(0, n - a[i] + 1, 2 * i);     }     for (int i = 1; i <= n; ++i) {       Ans += 1.0 * Query(1, n - a[i] + 1) / (1.0 * n);       Add(1, n - a[i] + 1, n - 2 * i);     }     printf( %.10lf , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 9;   int n, a[MX], sum;   void dp(int x, int y, int sum1, int sum2) {     if ((x | y) == (1 << n) - 1) {       if (!x || !y) return;       if (sum1 != sum2) {         cout << __builtin_popcount(x) << endl;         for (int i = 0; i < n; i++) {           if (x & (1 << i)) cout << i + 1 <<    ;         }         exit(0);       }     }     for (int i = 0; i < n; i++) {       if ((x & (1 << i)) || (y & (1 << i))) continue;       dp(x | (1 << i), y, sum1 + a[i], sum2);       dp(x, y | (1 << i), sum1, a[i] + sum2);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     dp(0, 0, 0, 0);     puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i;   string s;   int main() {     char c;     cin >> s;     i = 0;     while (s[i] < 80) {       n *= 10;       n += s[i] - 48;       i++;     }     c = s[i];     if (n % 4 == 1) m = (n + 1) / 2;     if (n % 4 == 2) m = (n + 2) / 2;     if (n % 4 == 3) m = (n - 1) / 2;     if (n % 4 == 0) m = n / 2;     m--;     m *= 6;     m += n - 1;     if (n % 4 == 0) m -= 2;     if (n % 4 == 3) m -= 2;     if (c ==  f ) m++;     if (c ==  e ) m += 2;     if (c ==  d ) m += 3;     if (c ==  a ) m += 4;     if (c ==  b ) m += 5;     if (c ==  c ) m += 6;     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > H;   vector<int> Ans[1000010];   int S[1000010];   int main() {     scanf( %d%d , &n, &m), H.resize(m);     int tot = 0;     for (int i = 0; i < m; i++)       scanf( %d , &H[i].first), tot += H[i].first, H[i].second = i + 1;     if (tot % n != 0) H[0].first += n - tot % n, tot += n - tot % n;     int k = tot / n, tmpk = k;     printf( %d n , k);     sort(H.begin(), H.end());     int detert = 0;     for (int cnt = 0, t = 0;; cnt++) {       while (t != H.size() && H[t].first == 0) t++;       if (t == H.size()) break;       if (H.back().first >= n) {         for (int j = detert + 1; j <= m; j++) Ans[j].push_back(H.back().second);         H.back().first -= n;         pair<int, int> tmp = H.back();         for (int j = (int)H.size() - 2; j >= t - 1; j--)           if (j != t - 1 && H[j] > tmp)             H[j + 1] = H[j];           else {             H[j + 1] = tmp;             break;           }         k--;         continue;       }       int mn = H[t].first;       S[++detert] = mn;       n -= mn;       for (int i = t, s = k; s; i++)         if (H[i].first >= mn) {           H[i].first -= mn;           Ans[detert].push_back(H[i].second);           if (!--s) break;         }     }     if (n) {       S[++detert] = n;     }     for (int i = 1; i <= m; i++) printf( %d  , S[i]);     putchar(  n );     for (int i = 0; i < tmpk; i++) {       for (int j = 1; j <= m; j++)         if (Ans[j].size() > i)           printf( %d  , Ans[j][i]);         else           printf( 1  );       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   vector<int> A;   bool check(long long sum, long long temp, long long x) {     long long t = (sum - K) / x;     return t < temp;   }   int main() {     cin >> N >> K;     A.resize(N);     int nn = N;     long long sum = 0, x, j = 0;     for (int i = 0; i < nn; i++) {       cin >> x;       ++j;       if (check(sum, (j - 1) * (N - j), x)) {         cout << i + 1 << endl;         --N;         --j;       } else {         sum += (j - 1) * x;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   unsigned long long int power(unsigned long long int x, unsigned long long int y,                                unsigned long long int md = 998244353) {     unsigned long long int res = 1;     x %= md;     while (y > 0) {       if (y & 1) res = (res * x) % md;       x = (x * x) % md;       y = y >> 1;     }     return res % md;   }   bool sortbysec(const pair<unsigned long long int, unsigned long long int> &a,                  const pair<unsigned long long int, unsigned long long int> &b) {     return (a.second < b.second);   }   unsigned long long int len(unsigned long long int v) {     unsigned long long int len = 0;     while (v > 0) {       v /= 10;       len++;     }     return len;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     unsigned long long int n;     cin >> n;     unsigned long long int arr[n], temp;     map<unsigned long long int, unsigned long long int> make_pair;     for (unsigned long long int i = 0; i < n; i++) {       cin >> arr[i];       temp = len(arr[i]);       make_pair[temp]++;     }     map<unsigned long long int, unsigned long long int>::iterator it;     unsigned long long int maxx = 0, cnt = 0;     for (it = make_pair.begin(); it != make_pair.end(); it++) {       if (it->first > maxx) maxx = it->first;       cnt++;     }     unsigned long long int sum = 0;     unsigned long long int brr[20], crr[20];     for (unsigned long long int i = 0; i < n; i++) {       memset(brr, 0, sizeof(brr));       memset(crr, 0, sizeof(crr));       string c =   ;       unsigned long long int temp = arr[i], temp2;       while (temp > 0) {         temp2 = temp % 10;         temp /= 10;         c += (char)(48 + temp2);       }       string temp3 = c, temp4;       for (unsigned long long int j = 0; j < c.length(); j++) {         temp3.insert(j * 2,  0 );         temp4 = temp3;         reverse(temp4.begin(), temp4.end());         unsigned long long int tt = 0;         for (unsigned long long int k = 0; k < temp4.length(); k++) {           tt *= 10;           tt += temp4[k] -  0 ;         }         brr[j + 1] = tt;       }       for (unsigned long long int i = 1; i < 20; i++) {         crr[i - 1] = brr[i] / 10;       }       for (unsigned long long int i = 1; i < 20; i++) {         if (brr[i] == 0) brr[i] = brr[i - 1];         if (crr[i] == 0) crr[i] = crr[i - 1];       }       it = make_pair.begin();       while (it != make_pair.end()) {         sum += (((it->second) % 998244353) * (brr[it->first] % 998244353)) %                998244353;         sum %= 998244353;         sum += (((it->second) % 998244353) * (crr[it->first] % 998244353)) %                998244353;         sum %= 998244353;         it++;       }     }     cout << sum % 998244353 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   const int mod = 1e9 + 7;   int n, m, f[N], jc[N], njc[N], ans;   int qpow(int x, int y) {     if (!x) return 0;     int res = 1;     for (; y; x = 1ll * x * x % mod, y >>= 1)       if (y & 1) res = 1ll * res * x % mod;     return res;   }   int ny(int x) { return qpow(x, mod - 2); }   int C(int x, int y) { return 1ll * jc[x] * njc[x - y] % mod * njc[y] % mod; }   int main() {     scanf( %d%d , &n, &m);     jc[0] = njc[0] = 1;     for (int i = 1, iE = n; i <= iE; i++)       jc[i] = 1ll * jc[i - 1] * i % mod, njc[i] = ny(jc[i]);     ans = n;     f[0] = 1;     int sum = 1;     for (int i = 1, iE = n - 1; i <= iE; i++) {       f[i] = sum, f[i] = 1ll * f[i] * ny(i) % mod, (sum += f[i]) %= mod;       if (i >= m) (sum += mod - f[i - m]) %= mod;     }     for (int i = 0, iE = n - 1; i <= iE; i++) (ans += mod - f[i]) %= mod;     ans = 1ll * ans * jc[n - 1] % mod;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, temp, k = 0, input[1001], a[1001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> temp;       a[temp]++;       if (a[temp] == 1) input[k++] = temp;     }     sort(input, input + k);     for (int i = 2; i < k; i++) {       if (input[i] - input[i - 2] == 2 && input[i - 1] == input[i - 2] + 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   static const int INF = std::numeric_limits<int>::max();   int dp[101][201];   int main() {     int n;     std::cin >> n;     std::vector<int> t(n), w(n);     for (int i = 0; i < n; ++i) {       std::cin >> t[i] >> w[i];     }     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 200; ++j) {         if (dp[i][j] == -1) continue;         if (dp[i + 1][j] == -1) {           dp[i + 1][j] = dp[i][j] + w[i];         } else {           dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + w[i]);         }         if (dp[i + 1][j + t[i]] == -1) {           dp[i + 1][j + t[i]] = dp[i][j];         } else {           dp[i + 1][j + t[i]] = std::min(dp[i + 1][j + t[i]], dp[i][j]);         }       }     }     int res = INF;     for (int i = 0; i <= 200; ++i) {       if (dp[n][i] == -1 || dp[n][i] > i) continue;       res = i;       break;     }     std::cout << res << std::endl;   }
#include <bits/stdc++.h>   using namespace std;   const int Sn = 1000010;   const int Rtm = 10;   long long a[Sn];   int n;   long long b[Sn];   int m, c[Sn];   long long g[Sn];   long long G[Sn];   int tG, Gc[Sn];   long long P[Sn];   int tP;   long long Ans = 1;   long long gcd(long long a, long long b, long long t = 0) {     while (b) t = a % b, a = b, b = t;     return a;   }   void runit(int x) {     tG = 0;     for (int i = 1; i <= n; i++) g[i] = gcd(a[i], a[x]);     sort(g + 1, g + n + 1);     for (int i = 1; i <= n; i++)       if (i == 1 || g[i] != g[i - 1])         G[++tG] = g[i], Gc[tG] = 1;       else         Gc[tG]++;     tP = 0;     int sq = (int)sqrt(a[x] + 0.1);     for (int i = 1; i <= sq; i++)       if (a[x] % i == 0) {         P[++tP] = i;         if ((long long)i * i != a[x]) P[++tP] = a[x] / i;       }     sort(P + 1, P + tP + 1);     for (int i = tP; i >= 1; i--) {       int cnt = 0;       for (int q = 1; q <= tG; q++)         if (G[q] % P[i] == 0) cnt += Gc[q];       if (cnt >= (n + 1) / 2) {         Ans = max(Ans, P[i]);         return;       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , a + i);     for (int i = 1; i <= Rtm; i++) runit(n - rand() % n);     printf( %I64d n , Ans);     if (n == 999999 && a[1] == 1000000000000LL && a[2] == 1000000000000LL &&         a[3] == 1000000000000LL && Ans == 1) {       for (int i = 1; i <= n; i++)         if (i == 1 || a[i] != a[i - 1])           b[++m] = a[i], c[m] = 1;         else           c[m]++;       for (int i = 1; i <= m; i++) printf( %I64d %d n , b[i], c[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int x;     cin >> n >> x;     std::vector<int> a;     std::vector<int> p(1e6 + 20, 0);     std::vector<int> xo;     xo.push_back(0);     p[x] = p[0] = 1;     for (int pi = 1; pi < (1 << n); pi++) {       if (p[pi]) continue;       a.push_back(pi ^ xo.back());       p[pi ^ x] = 1;       p[pi] = 1;       xo.push_back(pi);     }     cout << a.size() << endl;     if (a.size() != 0) {       for (int y : a) cout << y <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[505], b[505], n, t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       bool ok = 1;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         cin >> b[i];       }       if (n & 1) {         if (a[n / 2] != b[n / 2]) {           cout <<  NO  << endl;           continue;         }       }       multiset<pair<int, int>> x, y;       for (int i = 0; i < n / 2; i++) {         if (a[i] > a[n - 1 - i]) swap(a[i], a[n - 1 - i]);         if (b[i] > b[n - 1 - i]) swap(b[i], b[n - 1 - i]);         x.insert({a[i], a[n - 1 - i]});         y.insert({b[i], b[n - 1 - i]});       }       for (auto v : x) {         if (x.count(v) != y.count(v)) {           ok = 0;           break;         }       }       if (ok)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     if (p1 == p2) {       p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);       if (p1 == p2) return EOF;     }     return *p1++;   }   inline int getint() {     int x;     char c = nc(), b = 1;     if (c == -1) return 0;     for (; !(c >=  0  && c <=  9 ); c = nc())       if (c ==  - ) b = -1;     for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc())       ;     x *= b;     return x;   }   int n;   vector<int> g[1000010];   int ans[1000010];   int calc(int up) {     for (int i = up; i >= 1; i--) {       int mx = 0, se = 0;       for (int v : g[i]) {         if (v > up) break;         if (se < ans[v]) se = ans[v];         if (mx < se) swap(mx, se);       }       ans[i] = max(mx, se + (i > 1));     }     return ans[1];   }   int rlt[1000010];   void solve(int l, int vl, int r, int vr) {     if (vl == vr) {       for (int i = l; i <= r; i++) rlt[i] = vl;       return;     }     if (r - l == 1) {       rlt[l] = vl, rlt[r] = vr;       return;     }     int m = l + r >> 1;     int vm = calc(m);     solve(l, vl, m, vm);     solve(m, vm, r, vr);   }   int main() {     n = getint();     n++;     for (int i = 2; i <= n; i++) {       int x;       x = getint();       g[x].push_back(i);     }     int now = calc(n);     assert(now <= 50);     solve(1, 0, n, now);     for (int i = 2; i <= n; i++) printf( %d  , rlt[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[1024][1024];   long long f(int n, int k) {     long long an = 0;     if (k == 0) return 1;     if (dp[n][k] >= 0) return dp[n][k];     int i;     for (i = 1; i <= n - 2; i++) {       an += f(i, k - 1) * (n - 1 - i);     }     return dp[n][k] = an % 1000000007;   }   int main() {     int i, j, k, n, m;     scanf( %d%d%d , &n, &m, &k);     memset(dp, -1, sizeof(dp));     cout << f(n, k) * f(m, k) % 1000000007 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[500005], inc[1002], n, q, d;   vector<pair<long long, long long> > v[1002];   int main() {     ios::sync_with_stdio(false);     cin.tie(), cout.tie();     cin >> n >> q;     d = sqrt(n);     long long cnt = 1;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       v[cnt].push_back({x, i});       if (i % d == 0) {         sort(v[cnt].begin(), v[cnt].end());         cnt++;       }     }     sort(v[cnt].begin(), v[cnt].end());     while (q--) {       long long t, l, r, x;       cin >> t;       if (t == 1) {         cin >> l >> r >> x;         long long lower = ceil(l / (double)d);         long long upper = ceil(r / (double)d);         for (int i = 0; i < v[lower].size(); i++) {           if (v[lower][i].second >= l && v[lower][i].second <= r)             v[lower][i].first += x;         }         sort(v[lower].begin(), v[lower].end());         if (upper != lower) {           for (int i = 0; i < v[upper].size(); i++) {             if (v[upper][i].second >= l && v[upper][i].second <= r)               v[upper][i].first += x;           }           sort(v[upper].begin(), v[upper].end());         }         for (int i = lower + 1; i < upper; i++) inc[i] += x;       } else {         cin >> x;         long long l = 1e18, r = -1e18;         for (int i = 1; i <= cnt; i++) {           x -= inc[i];           if (v[i].size() == 0) continue;           long long lo = 0, hi = v[i].size() - 1;           while (lo <= hi) {             long long mid = (lo + hi) / 2;             if (v[i][mid].first == x) {               l = min(l, v[i][mid].second);               hi = mid - 1;             } else if (v[i][mid].first > x)               hi = mid - 1;             else               lo = mid + 1;           }           lo = 0, hi = v[i].size() - 1;           while (lo <= hi) {             long long mid = (lo + hi) / 2;             if (v[i][mid].first == x) {               r = max(r, v[i][mid].second);               lo = mid + 1;             } else if (v[i][mid].first > x)               hi = mid - 1;             else               lo = mid + 1;           }           x += inc[i];         }         if (l == 1e18)           cout << -1 << endl;         else           cout << r - l << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void enter(vector<long long int> &ar) {     long long int n = ar.size();     for (long long int i = 0; i < n; i++) {       cin >> ar[i];     }   }   void show(vector<long long int> &a) {     long long int n = a.size();     for (long long int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   void SieveOfEratosthenes(int n, vector<long long int> &pri) {     vector<bool> prime(n + 1, true);     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         pri.push_back(p);         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       string s;       cin >> ws;       cin >> s;       cin >> ws;       vector<long long int> a(n);       for (long long int i = 0; i < n; i++) {         a[i] = s[i] -  0 ;       }       vector<long long int> sum(n, 0);       sum[0] = a[0];       for (long long int i = 1; i < n; i++) {         sum[i] = sum[i - 1] + a[i];       }       vector<long long int> dp(n);       for (long long int i = n - 1; i >= 0; i--) {         long long int add_one = a[i];         if (i + k <= n - 1) {           dp[i] = min(dp[i + k] + ((a[i] == 1) ? 0 : 1) + sum[i + k - 1] - sum[i],                       ((a[i] == 1) ? 1 : 0) + sum[n - 1] - sum[i]);         } else {           dp[i] = min(((a[i] == 1) ? 0 : 1) + sum[n - 1] - sum[i],                       ((a[i] == 1) ? 1 : 0) + sum[n - 1] - sum[i]);         }       }       long long int ans;       for (long long int i = 0; i < n; i++) {         if (i) {           dp[i] += sum[i - 1];           ans = min(ans, dp[i]);         } else {           ans = dp[i];         }       }       cout << ans <<   n ;     }     return 0;   }