malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int N = 1000 + 20;   int n, m, q, part[N][N];   string s[N];   inline int get(int x) { return (__builtin_popcount(x) & 1 ? -1 : +1); }   inline int get(int x, int y) { return get(x) * get(y); }   inline pii calc(int x) {     int a = x / 2, b = x / 2;     if (x & 1) {       if (get(x - 1) == 1)         a++;       else         b++;     }     return pii(a, b);   }   inline pii calc(int x, int y) {     pii p1 = calc(x), p2 = calc(y);     return pii(p1.first * p2.first + p1.second * p2.second,                p1.first * p2.second + p1.second * p2.first);   }   inline int f(int x, int y) {     int res = 0;     int X = x / n, Y = y / m;     x %= n, y %= m;     pii p = calc(X, Y);     res += part[n][m] * p.first + (n * m - part[n][m]) * p.second;     p = calc(X);     if (get(Y) == -1) swap(p.first, p.second);     res += part[n][y] * p.first + (n * y - part[n][y]) * p.second;     p = calc(Y);     if (get(X) == -1) swap(p.first, p.second);     res += part[x][m] * p.first + (x * m - part[x][m]) * p.second;     if (get(X, Y) == 1)       res += part[x][y];     else       res += (x * y - part[x][y]);     return res;   }   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> q;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < m; j++) {         part[i + 1][j + 1] =             (s[i][j] ==  1 ) + part[i][j + 1] + part[i + 1][j] - part[i][j];       }     }     while (q--) {       int x1, hlkhjl, x2, y2;       cin >> x1 >> hlkhjl >> x2 >> y2;       x1--, hlkhjl--;       cout << f(x2, y2) - f(x1, y2) - f(x2, hlkhjl) + f(x1, hlkhjl) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long a, b, m;     long long vx, vy, vz;     cin >> a >> b >> m >> vx >> vy >> vz;     double time = -((double)(m) / (double)(vy));     double xc = (double)(a) / 2.0 + time * vx;     if (xc >= 0) {       long long p = xc / a;       if (p % 2 == 1) {         xc = (p + 1) * a - xc;       } else {         xc -= p * a;       }     } else {       long long p = xc / a;       if (p % 2 == 0) {         xc -= p * a;         xc = -xc;       } else {         xc -= p * a;         xc = -xc;         xc = a - xc;       }     }     double zc = time * vz;     if (zc >= 0) {       long long p = zc / b;       if (p % 2 == 1) {         zc = (p + 1) * b - zc;       } else {         zc -= p * b;       }     } else {       long long p = zc / b;       if (p % 2 == 0) {         zc -= p * b;         zc = -zc;       } else {         zc -= p * b;         zc = -zc;         zc = b - zc;       }     }     printf( %0.12llf %0.12llf , xc, zc);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 7;   long long a[MAXN];   int n, k, x;   void print() {     for (int i = 1; i <= n; ++i) cout << a[i] <<    ;     exit(0);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k >> x;     vector<int> zeros;     int n_pos = 0, n_neg = 0, n_zer = 0;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (a[i] > 0) ++n_pos;       if (a[i] < 0) ++n_neg;       if (a[i] == 0) ++n_zer, zeros.push_back(i);     }     if (n_zer) {       if (n_zer > k) print();       if ((n_zer & 1) == (n_neg & 1))         a[zeros.back()] += 1LL * x, zeros.pop_back(), ++n_pos, --k;       for (auto v : zeros) a[v] -= 1LL * x, ++n_neg, --k;     }     set<pair<long long, int> > s;     for (int i = 1; i <= n; ++i) s.insert({abs(a[i]), i});     if ((n_neg & 1) == 0) {       int id = s.begin()->second;       bool save = (a[id] > 0);       s.erase(s.begin());       while (k && (a[id] == 0 || ((a[id] > 0) == save))) {         if (save)           a[id] -= 1LL * x;         else           a[id] += 1LL * x;         --k;       }       if (k == 0) print();       s.insert({abs(a[id]), id});     }     while (k--) {       int id = s.begin()->second;       s.erase(s.begin());       if (a[id] > 0)         a[id] += 1LL * x;       else         a[id] -= 1LL * x;       s.insert({abs(a[id]), id});     }     print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e6 + 10;   int n, k, count1;   int a[MAX];   int res = 1e19 + 10;   int binary_search1(int x, int l, int r) {     int res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[mid] <= x) {         res = mid;         l = mid + 1;       } else         r = mid - 1;     }     return res;   }   int binary_search2(int x, int l, int r) {     int res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (a[mid] < x) {         l = mid + 1;       } else {         res = mid;         r = mid - 1;       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     scanf( %d %d n , &n, &k);     count1 = 0;     for (int i = 1; i <= n; i++) {       char s;       scanf( %c , &s);       if (s ==  0 ) {         a[++count1] = i;       }     }     sort(a + 1, a + 1 + count1);     k += 1;     for (int i = 1; i <= count1 - k + 1; i++) {       int l = i;       int r = k + i - 1;       int pos1 = binary_search1((a[l] + a[r]) >> 1, l, r);       int pos2 = binary_search2((a[l] + a[r]) >> 1, l, r);       if (pos1 != 0) {         res = min(res, max(a[pos1] - a[l], a[r] - a[pos1]));       }       if (pos2 != 0) {         res = min(res, max(a[pos2] - a[l], a[r] - a[pos2]));       }     }     printf( %d , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7fffffff;   const int Size = 1000 * 1000 + 1;   char buffer[Size];   int solution(int nTest) {     int n, m, K;     scanf( %d%d%d , &n, &m, &K);     vector<string> name;     vector<vector<int> > a, b, c;     for (int i = 0; i < n; i++) {       scanf( %s , buffer);       name.push_back(buffer);       int ta, tb, tc;       vector<int> va, vb, vc;       for (int j = 0; j < m; j++) {         scanf( %d%d%d , &ta, &tb, &tc);         va.push_back(ta);         vb.push_back(tb);         vc.push_back(tc);       }       a.push_back(va);       b.push_back(vb);       c.push_back(vc);     }     int res = 0;     for (int i = 0; i < n; i++) {       for (int k = 0; k < n; k++) {         int t = K;         vector<pair<int, int> > v;         for (int j = 0; j < m; j++) {           v.push_back(make_pair(b[k][j] - a[i][j], j));         }         sort(v.begin(), v.end());         reverse(v.begin(), v.end());         int sum = 0;         for (int j = 0; j < m; j++) {           if (v[j].first >= 0) {             int ct = c[i][v[j].second];             if (t >= ct) {               sum += ct * v[j].first;               t -= ct;             } else {               sum += t * v[j].first;               t = 0;             }           }         }         res = max(res, sum);       }     }     printf( %d n , res);     return 0;   }   int main() {     if (0) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int i = 0, n = 99999;     while (i < n && solution(i)) {       i++;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5, V = 5;   const unsigned long long MOD = 1ull << 58, INV5 = 14757395258967641293ull;   struct Com {     unsigned long long a[V];     inline void clear() { a[0] = a[1] = a[2] = a[3] = a[4] = 0; }     inline Com() { clear(); }     inline unsigned long long &operator[](int x) { return a[x]; }     inline const unsigned long long &operator[](const int &x) const {       return a[x];     }     inline Com operator+(const Com &b) const {       Com c;       for (int i = 0; i < V; i++) c[i] = a[i] + b[i];       return c;     }     inline Com operator-(const Com &b) const {       Com c;       for (int i = 0; i < V; i++) c[i] = a[i] - b[i];       return c;     }     inline Com operator*(const unsigned long long &b) const {       Com c;       for (int i = 0; i < V; i++) c[i] = a[i] * b;       return c;     }     inline Com operator*(const Com &b) const {       static unsigned long long d[V << 1];       for (int i = 0; i < V; i++)         for (int j = 0; j < V; j++) d[i + j] += a[i] * b[j];       Com c;       for (int i = 0; i < V; i++) c[i] = d[i] + d[i + V], d[i] = d[i + V] = 0;       return c;     }     inline Com &operator+=(const Com &b) { return *this = *this + b; }     inline Com &operator*=(const unsigned long long &b) {       return *this = *this * b;     }     inline Com &operator*=(const Com &b) { return *this = *this * b; }     inline void out() {       printf( (%llu,%llu,%llu,%llu,%llu) n , a[0], a[1], a[2], a[3], a[4]);     }     inline unsigned long long val() { return (a[0] - a[4]) >> 5; }     inline bool operator!=(const Com &b) const {       for (int i = 0; i < V; i++)         if (a[i] != b[i]) return 1;       return 0;     }   } w[2][V << 1], a[N];   inline Com qpow(Com a, int b) {     Com c;     c[0] = 1;     for (; b; b >>= 1, a *= a)       if (b & 1) c *= a;     return c;   }   inline void pre() {     w[0][0][0] = w[1][0][0] = 1;     w[0][1][3] = w[1][1][2] = -1;     for (int i = 2; i < V << 1; i++) {       w[0][i] = w[0][i - 1] * w[0][1], w[1][i] = w[1][i - 1] * w[1][1];     }   }   const int pw[V] = {1, 10, 100, 1000, 10000};   inline void fft(int opt) {     for (int i = 0; i < V; i++)       for (int j = 0; j < N; j++)         if (!((j / pw[i]) % 10)) {           static Com f[V << 1];           for (int a = 0; a < V << 1; a++)             for (int b = 0; b < V << 1; b++) {               f[a] += ::a[j + b * pw[i]] *                       (opt ? w[0][(10 - a * b % 10) % 10] : w[0][a * b % 10]);             }           for (int a = 0; a < V << 1; a++) {             ::a[j + a * pw[i]] = f[a];             f[a].clear();           }         }     if (opt) {       unsigned long long INV = INV5 * INV5 * INV5 * INV5 * INV5;       for (int i = 0; i < N; i++) a[i] *= INV;     }   }   int n;   int main() {     pre();     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       a[x][0]++;     }     fft(0);     for (int i = 0; i < N; i++) a[i] = qpow(a[i], n);     fft(1);     for (int i = 0; i < n; i++) printf( %llu n , a[i].val() % MOD);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int maxn = 2e5;   const int INF = 0x7fffffff;   const int mod = 1e9 + 7;   const double eps = 1e-7;   const double Pi = acos(-1.0);   inline int read_int() {     char c;     int ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   inline long long read_ll() {     char c;     long long ret = 0, sgn = 1;     do {       c = getchar();     } while ((c <  0  || c >  9 ) && c !=  - );     if (c ==  - )       sgn = -1;     else       ret = c -  0 ;     while ((c = getchar()) >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     return sgn * ret;   }   int n, arr[maxn + 5], res[maxn + 5];   vector<int> dc, ic;   int main() {     n = read_int();     for (int i = 1; i <= n; ++i) arr[i] = read_int();     for (int i = 1; i <= n; ++i) {       if (dc.empty() && ic.empty()) {         if (i < n && arr[i] <= arr[i + 1])           ic.push_back(i);         else           dc.push_back(i);       } else if (dc.empty()) {         int id = ic.back();         if (arr[i] <= arr[id])           dc.push_back(i);         else {           if (i + 1 <= n && arr[i] <= arr[i + 1])             ic.push_back(i);           else             dc.push_back(i);         }       } else if (ic.empty()) {         int id = dc.back();         if (arr[i] >= arr[id])           ic.push_back(i);         else {           if (i + 1 <= n && arr[i] <= arr[i + 1])             ic.push_back(i);           else             dc.push_back(i);         }       } else {         int id1 = ic.back(), id2 = dc.back();         if (arr[i] <= arr[id1] && arr[i] >= arr[id2]) {           cout <<  NO  << endl;           return 0;         } else if (arr[i] > arr[id1] && arr[i] < arr[id2]) {           if (i + 1 <= n && arr[i] <= arr[i + 1])             ic.push_back(i);           else             dc.push_back(i);         } else if (arr[i] > arr[id1])           ic.push_back(i);         else           dc.push_back(i);       }     }     for (int i = 0; i < dc.size(); ++i) res[dc[i]] = 1;     cout <<  YES  << endl;     for (int i = 1; i <= n; ++i) printf( %d%c , res[i],    n [i == n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 505, maxmax = 1000000;   int n, javab[maxn][maxn];   vector<int> v;   int dp(int l, int r) {     int x = maxmax;     if (l == r) {       javab[l][r] = 1;       return 1;     }     if (l == r - 1) {       if (v[r] == v[l]) {         javab[l][r] = 1;         return 1;       } else {         javab[l][r] = 2;         return 2;       }     }     if (javab[l][r - 1] != 0)       x = min(x, javab[l][r - 1] + 1);     else {       x = min(x, dp(l, r - 1) + 1);     }     for (int i = r - 1; i >= l; i--) {       if (v[r] == v[i]) {         if (i == l) {           if (javab[l + 1][r - 1] != 0) {             x = min(x, javab[l + 1][r - 1]);           } else             x = min(x, dp(l + 1, r - 1));           break;         }         if (javab[l][i - 1] != 0) {           if (javab[i][r] != 0) {             x = min(x, javab[l][i - 1] + javab[i][r]);           } else {             x = min(x, javab[l][i - 1] + dp(i, r));           }         } else {           if (javab[i][r] != 0) {             x = min(x, dp(l, i - 1) + javab[i][r]);           } else {             x = min(x, dp(l, i - 1) + dp(i, r));           }         }       }     }     javab[l][r] = x;     return x;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       v.push_back(x);     }     int javab = dp(0, v.size() - 1);     cout << javab;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   using namespace std;   template <typename T>   void uin(T &a, T b) {     if (b < a) {       a = b;     }   }   template <typename T>   void uax(T &a, T b) {     if (b > a) {       a = b;     }   }   const long long N = 100 * 1000 + 228;   vector<long long> g[N];   long long deg[N];   long long h[N], p[N];   void dfs(long long v, long long par = -1) {     h[v] = (par == -1 ? 0 : h[par] + 1);     p[v] = par;     for (long long to : g[v]) {       if (to != par) dfs(to, v);     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n - 1; ++i) {       long long u, v;       cin >> u >> v;       ++deg[u];       ++deg[v];       g[u].emplace_back(v);       g[v].emplace_back(u);     }     long long root = 1;     for (long long i = 1; i <= n; ++i) {       if (deg[i] > 1) {         root = i;         break;       }     }     dfs(root);     bool even = 0, odd = 0;     for (long long i = 1; i <= n; ++i) {       if (deg[i] == 1) {         if (h[i] & 1)           odd = 1;         else           even = 1;       }     }     long long min_colors = 0;     if (even && odd) {       min_colors = 3;     } else {       min_colors = 1;     }     vector<long long> pars;     long long leafs = 0;     for (long long i = 1; i <= n; ++i) {       if (deg[i] == 1) {         pars.emplace_back(p[i]);         ++leafs;       }     }     sort(pars.begin(), pars.end());     pars.erase(unique(pars.begin(), pars.end()), pars.end());     long long max_colors = (long long)pars.size();     max_colors += (n - 1 - leafs);     cout << min_colors <<     << max_colors <<   n ;     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 MAXLEN = 15;   long long dp[MAXLEN + 1][2];   long long dpleq[MAXLEN + 1][2];   inline int conv(char c) {     if (isdigit(c)) return c -  0 ;     if (islower(c)) return c -  a  + 10;     assert(false);   }   long long calc(char* s) {     int slen = strlen(s);     long long ret = 0;     for (int mx = (0); mx < (16); ++mx) {       int pos = mx / 4, off = mx % 4;       if (pos >= slen) continue;       memset(dp, 0, sizeof(dp));       memset(dpleq, 0, sizeof(dpleq));       dp[0][0] = dpleq[0][0] = 1;       for (int i = (0); i < (slen); ++i)         for (int j = (0); j < (2); ++j)           for (int k = (0); k <= (mx); ++k) {             if (i == pos && (k & (1 << off)) == 0) continue;             int nj = j == 1 || k == mx ? 1 : 0;             dp[i + 1][nj] += dp[i][j];             if (k < conv(s[i]))               dpleq[i + 1][nj] += dp[i][j];             else if (k == conv(s[i]))               dpleq[i + 1][nj] += dpleq[i][j];           }       long long cur = dpleq[slen][1];       ret += cur;     }     return ret;   }   void dec(char* s) {     for (int i = 0;; ++i)       if (s[i] ==  0 )         s[i] =  f ;       else {         assert(s[i] !=   0 );         if (s[i] ==  a )           s[i] =  9 ;         else           --s[i];         break;       }     int slen = strlen(s);     while (slen >= 2 && s[slen - 1] ==  0 ) --slen;     s[slen] =   0 ;   }   int nq;   char sl[MAXLEN + 1], sr[MAXLEN + 1];   long long solve() {     reverse(sl, sl + strlen(sl));     reverse(sr, sr + strlen(sr));     long long ret = calc(sr);     if (strcmp(sl,  0 ) != 0) {       dec(sl);       ret -= calc(sl);     }     return ret;   }   void run() {     scanf( %d , &nq);     for (int qi = (0); qi < (nq); ++qi) {       scanf( %s%s , sl, sr);       printf( %lld n , solve());     }   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int ans = 0;     int score = -1;     for (int i = 0; i < n; i++) {       int sub, subsc = 0;       scanf( %d , &sub);       subsc += sub;       scanf( %d , &sub);       subsc += sub;       scanf( %d , &sub);       subsc += sub;       scanf( %d , &sub);       subsc += sub;       if (subsc > score) {         ans++;       }       if (!i) score = subsc;     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 450, inf = 1e8;   int n1, n2, m, r, b, node, s, t, S, T, a[N], id[N];   char col1[N], col2[N];   int head[N], ce = 1, inq[N], dis[N], maxflow, mincost, need;   struct edge {     int to, nxt, cap, flow, w;   } e[5000];   void lnk(int a, int b, int c, int w) {     e[++ce] = (edge){b, head[a], c, 0, w}, head[a] = ce;     e[++ce] = (edge){a, head[b], 0, 0, -w}, head[b] = ce;   }   bool bfs() {     for (int i = 1; i <= node; ++i) dis[i] = inf, inq[i] = 0;     dis[s] = 0, inq[s] = 1;     queue<int> q;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         if (e[i].cap > e[i].flow && dis[v] > dis[u] + e[i].w) {           dis[v] = dis[u] + e[i].w;           if (!inq[v]) q.push(v), inq[v] = 1;         }       }       inq[u] = 0;     }     return dis[t] < inf;   }   int dfs(int u, int lim) {     if (u == t) return mincost += dis[t] * lim, lim;     int tag = 0;     inq[u] = 1;     for (int i = head[u]; i; i = e[i].nxt)       if (e[i].cap > e[i].flow && dis[e[i].to] == dis[u] + e[i].w &&           !inq[e[i].to]) {         int d = dfs(e[i].to, min(lim - tag, e[i].cap - e[i].flow));         tag += d, e[i].flow += d, e[i ^ 1].flow -= d;         if (tag == lim) {           inq[u] = 0;           return tag;         }       }     return tag;   }   int main() {     scanf( %d%d%d%d%d , &n1, &n2, &m, &r, &b);     scanf( %s , col1 + 1);     scanf( %s , col2 + 1);     node = n1 + n2, S = ++node, T = ++node, s = ++node, t = ++node;     for (int i = 1; i <= n1; ++i)       if (col1[i] ==  R )         ++a[i], --a[S], lnk(S, i, inf, 0);       else if (col1[i] ==  B )         --a[i], ++a[T], lnk(i, T, inf, 0);       else         lnk(S, i, inf, 0), lnk(i, T, inf, 0);     for (int i = 1; i <= n2; ++i)       if (col2[i] ==  R )         --a[i + n1], ++a[T], lnk(i + n1, T, inf, 0);       else if (col2[i] ==  B )         ++a[i + n1], --a[S], lnk(S, i + n1, inf, 0);       else         lnk(S, i + n1, inf, 0), lnk(i + n1, T, inf, 0);     for (int i = 1; i <= T; ++i)       if (a[i] > 0)         lnk(s, i, a[i], 0), need += a[i];       else if (a[i] < 0)         lnk(i, t, -a[i], 0);     lnk(T, S, inf, 0);     for (int i = 1, u, v; i <= m; ++i)       scanf( %d%d , &u, &v), id[i] = ce + 1, lnk(u, v + n1, 1, r),                              lnk(v + n1, u, 1, b);     while (bfs()) maxflow += dfs(s, inf);     if (maxflow < need) {       puts( -1 );       return 0;     }     printf( %d n , mincost);     for (int i = 1; i <= m; ++i)       if (e[id[i]].flow)         putchar( R );       else if (e[id[i] + 2].flow)         putchar( B );       else         putchar( U );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int search_factor(int n) {     if (n % 2 == 0) {       return n / 2;     } else {       for (int i = (n - 1) / 2; i >= 1; i -= 1) {         if (n % i == 0) return i;       }     }   }   int main() {     int n;     cin >> n;     long long int sum = n;     while (n != 1) {       int res = search_factor(n);       sum += res;       n = res;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void rd(long long &x) { scanf( %lld , &x); }   void rd(long long &x, long long &y) { scanf( %lld%lld , &x, &y); }   void rd(long long &x, long long &y, long long &z) {     scanf( %lld%lld%lld , &x, &y, &z);   }   void rd(long long &x, long long &y, long long &z, long long &s) {     scanf( %lld%lld%lld%lld , &x, &y, &z, &s);   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   void faltu() { cerr << endl; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr << endl;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   string s;   const long long N = 2e5 + 5;   long long n, m, cnt[N], mx[N][2];   bool visit[N];   pair<long long, long long> dp[N];   pair<long long, long long> back(long long pos) {     if (pos >= n) return make_pair(0LL, 0LL);     if (visit[pos]) return dp[pos];     visit[pos] = 1;     pair<long long, long long> &r = dp[pos];     r = back(pos + 1);     if (mx[pos][0] == m) {       pair<long long, long long> q = back(pos + m);       q.first++;       q.second += cnt[pos + m - 1];       if (pos) q.second -= cnt[pos - 1];       if (q.first > r.first || (q.first == r.first && q.second < r.second)) r = q;     }     return r;   }   int main() {     rd(n);     cin >> s;     rd(m);     for (long long i = 0; i < (n); i++) {       cnt[i] = (s[i] ==  ? );       if (i) cnt[i] += cnt[i - 1];     }     for (int i = n; i < N; i++) cnt[i] = cnt[i - 1];     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  a ) {         mx[i][0] = min(mx[i + 1][1] + 1, m);         mx[i][1] = 0;       } else if (s[i] ==  b ) {         mx[i][1] = min(mx[i + 1][0] + 1, m);         mx[i][0] = 0;       } else {         mx[i][0] = min(mx[i + 1][1] + 1, m);         mx[i][1] = min(mx[i + 1][0] + 1, m);       }     }     pair<long long, long long> p = back(0);     cout << (long long)p.second;     return 0;   }