malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   int n, m;   char grid[1005][1005];   int startX, startY, endX, endY;   int cost[1005][1005];   int lookDir[1005][1005];   bool vis[1005][1005];   bool isValid(int i, int j) {     return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] !=  * ;   }   void bfs() {     queue<pair<int, int> > q;     q.push({startX, startY});     cost[startX][startY] = 0;     lookDir[startX][startY] = 4;     vis[startX][startY] = 1;     while (q.size()) {       int x = q.front().first;       int y = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int xx = x + dx[i], yy = y + dy[i];         if (isValid(xx, yy) && (!vis[xx][yy] || cost[x][y] + 1 <= cost[xx][yy])) {           if (lookDir[x][y] == 4) {             if (dx[i] == 1) lookDir[xx][yy] = 3;             if (dx[i] == -1) lookDir[xx][yy] = 1;             if (dy[i] == 1) lookDir[xx][yy] = 2;             if (dy[i] == -1) lookDir[xx][yy] = 0;           } else if (lookDir[x][y] == 3 || lookDir[x][y] == 1) {             if (dy[i] != 0) cost[xx][yy] = cost[x][y] + 1;             if (dy[i] == -1) lookDir[xx][yy] = 0;             if (dy[i] == 1) lookDir[xx][yy] = 2;             if (dy[i] == 0)               lookDir[xx][yy] = lookDir[x][y], cost[xx][yy] = cost[x][y];           } else if (lookDir[x][y] == 0 || lookDir[x][y] == 2) {             if (dx[i] != 0) cost[xx][yy] = cost[x][y] + 1;             if (dx[i] == -1) lookDir[xx][yy] = 1;             if (dx[i] == 1) lookDir[xx][yy] = 3;             if (dx[i] == 0)               lookDir[xx][yy] = lookDir[x][y], cost[xx][yy] = cost[x][y];           }           vis[xx][yy] = 1;           q.push({xx, yy});         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  S ) startX = i, startY = j;         if (grid[i][j] ==  T ) endX = i, endY = j;       }     bfs();     if (cost[endX][endY] <= 2 && vis[endX][endY])       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using std::abs;   using std::cerr;   using std::cin;   using std::cout;   using std::endl;   using std::make_pair;   using std::max;   using std::min;   using std::pair;   using std::string;   using std::vector;   template <typename T>   inline T input() {     T ans;     cin >> ans;     return ans;   }   template <typename FloatT>   struct vec2 {    public:     vec2() {}     template <typename OtherT>     vec2(vec2<OtherT> other) : x(other.x), y(other.y) {}     vec2(FloatT x, FloatT y) : x(x), y(y) {}     vec2<FloatT> operator-(vec2<FloatT> other) {       return vec2<FloatT>(x - other.x, y - other.y);     }     vec2<FloatT> operator+(vec2<FloatT> other) {       return vec2<FloatT>(x + other.x, y + other.y);     }     vec2<FloatT> operator*(FloatT num) { return vec2<FloatT>(num * x, num * y); }     FloatT len() { return std::sqrt(x * x + y * y); }     FloatT x;     FloatT y;   };   const uint32_t num_iterations = 100000;   int main() {     vec2<int32_t> src;     vec2<int32_t> dest;     int32_t v, t;     vec2<int32_t> wind_before;     vec2<int32_t> wind_after;     cin >> src.x >> src.y >> dest.x >> dest.y;     cin >> v >> t;     cin >> wind_before.x >> wind_before.y >> wind_after.x >> wind_after.y;     if ((vec2<long double>(src - dest) + vec2<long double>(wind_before) * t)             .len() <= v * t) {       float left = 0;       float right = t;       for (uint32_t i = 0; i != num_iterations; ++i) {         float mid = left + (right - left) / 2;         if ((vec2<long double>(src - dest) + vec2<long double>(wind_before) * mid)                 .len() <= v * mid)           right = mid;         else           left = mid;       }       cout.precision(20);       cout << std::fixed << right << endl;     } else {       vec2<long double> new_src =           vec2<long double>(src) + vec2<long double>(wind_before) * t;       float left = 0;       float right = 1000000000;       for (uint32_t i = 0; i != num_iterations; ++i) {         float mid = left + (right - left) / 2;         if ((new_src - vec2<long double>(dest) +              vec2<long double>(wind_after) * mid)                 .len() <= v * (t + mid))           right = mid;         else           left = mid;       }       cout.precision(20);       cout << std::fixed << t + right << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;      const int N = 1000006;   const int MOD = 1000000007;      int bpow(int a, int b){       int res = 1;       while(b){           if(b&1) res = 1ll*res*a%MOD;           a = 1ll*a*a%MOD;           b >>= 1;       }       return res;   }      int inv(int a){return bpow(a, MOD-2);}      int n;   int fact[N], pw[N], ifact[N];      int comb(int a, int b){       if(a < 0 || b < 0) return 0;       if(a < b) return 0;       return 1ll*fact[a]*(1ll*ifact[b]*ifact[a-b]%MOD)%MOD;   }      int main(){       // freopen( a.in ,  r , stdin);       ios_base::sync_with_stdio(false);       cin.tie(0);       fact[0] = 1;       for(int i = 1; i<N; i++)           fact[i] = 1ll*fact[i-1]*i%MOD;       for(int i = 0; i<N; i++)           ifact[i] = inv(fact[i]);       pw[0] = 1;       for(int i = 1; i<N; i++)           pw[i] = 2*pw[i-1]%MOD;       cin >> n; int ans = 0;       for(int i = n%2; i<=n/2; i+=2){           int ways = 2ll*(0ll+comb(n-i+1, i)-comb(n-i-1, i-2)+MOD)%MOD;           int a = (n-i+1)/2, b = n-i-a;           ways = 1ll*ways*fact[a]%MOD;           ways = 1ll*ways*fact[b]%MOD;           ways = 1ll*ways*comb(n-i, a)%MOD;           ans = (ans+ways)%MOD;       }       cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, a[200005 / 2], ans = -1, cnt = 0;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k;     for (int i = 1; i <= n + 1; i++) {       if (i < n + 1)         cin >> a[i];       else         a[i] = a[i - 1];       if (a[i] != a[i - 1])         cnt++;       else {         ans = max(ans, cnt);         cnt = 1;       }       ans = max(ans, cnt);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long pw(long long a, long long k, long long p) {     if (k == 0) return 1;     return (k % 2 == 0 ? pw((a * a) % p, k / 2, p) : (a * pw(a, k - 1, p)) % p);   }   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 0 << endl;       return 0;     }     vector<long long> V(n);     for (int i = 0; i < n; ++i) cin >> V[i];     sort(V.begin(), V.end());     long long ans = 0, d = 1, s = 0, P = 1000000007;     long long dm = pw(2, n - 2, P), odw = pw(2, P - 2, P);     for (int i = 0; i < n / 2; ++i) {       s += V[n - i - 1] - V[i];       s %= P;       if (n % 2 != 0 || i != n / 2 - 1)         ans += s * (d + dm);       else         ans += s * d;       ans %= P;       dm = (dm * odw) % P;       d = (d * 2) % P;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 100 + 5;   const int mod = 1000 * 1000 * 1000 + 7;   const int maxM = 400000;   char a[102][102];   int c[maxN], cnt[maxN], p[maxN];   int main() {     ios::sync_with_stdio(0);     cin.tie();     srand(time(NULL));     int n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) cin >> c[i];     set<pair<int, int> > ss;     for (int i = 0; i < n; i++) ss.insert({c[i], i});     vector<int> ans;     while (ss.size()) {       while (ss.size() && ss.begin()->first < 0) ss.erase(ss.begin());       if (ss.size() == 0 || ss.begin()->first > 0) break;       auto it = *ss.begin();       int v = it.second;       ans.push_back(v);       for (int i = 0; i < n; i++)         if (a[v][i] ==  1  && c[i] >= 0) {           ss.erase({c[i], i});           c[i]--;           ss.insert({c[i], i});         }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = int(2e9) + 9;   const double eps = 1e-9;   const double pi = 3.14159265358979323846264338327950;   int main() {     string str;     cin >> str;     char X[5];     int cnt[200];     cnt[ R ] = 0, cnt[ G ] = 0, cnt[ B ] = 0, cnt[ Y ] = 0;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  R ) X[i % 4] =  R ;       if (str[i] ==  B ) X[i % 4] =  B ;       if (str[i] ==  Y ) X[i % 4] =  Y ;       if (str[i] ==  G ) X[i % 4] =  G ;     }     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  ! ) {         str[i] = X[i % 4];         cnt[str[i]]++;       }     }     cout << cnt[ R ] <<     << cnt[ B ] <<     << cnt[ Y ] <<     << cnt[ G ]          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300 * 1000 + 10;   pair<int, int> c[MAX_N];   int t[MAX_N];   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> c[i].first, c[i].second = i;     set<int> s;     for (int i = k; i < n + k; i++) s.insert(i);     sort(c, c + n);     long long ans = 0;     for (int i = n - 1; ~i; i--) {       int id = c[i].second;       s.erase(t[id] = *s.lower_bound(id));       ans += 1LL * abs(t[id] - id) * c[i].first;     }     cout << ans << endl;     for (int i = 0; i < n; i++) cout << t[i] + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     if (flag) x = -x;   }   int T, n, m;   int a[1000010];   pair<long long, long long> ans;   bool cmp(const int &x, const int &y) { return x > y; }   long long qp(long long x, long long y, long long p) {     long long v = 1;     while (y) {       if (y & 1) v = v * x % p;       x = x * x % p, y >>= 1;     }     return v;   }   int main() {     read(T);     while (T--) {       read(n), read(m), ans.first = ans.second = 0;       for (int i = 1; i <= n; ++i) read(a[i]);       sort(a + 1, a + n + 1, cmp);       for (int i = 1; i <= n; ++i) {         if (!ans.first && !ans.second) {           ans.first = (ans.first + qp(m, a[i], 1000000007)) % 1000000007;           ans.second = (ans.second + qp(m, a[i], 19260817)) % 19260817;         } else {           ans.first =               (ans.first - qp(m, a[i], 1000000007) + 1000000007) % 1000000007;           ans.second = (ans.second - qp(m, a[i], 19260817) + 19260817) % 19260817;         }       }       printf( %lld n , ans.first);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10;   struct ft_t {     long long d[N], t[N];     void init() {       memset(d, 0, sizeof(d));       memset(t, 0, sizeof(t));     }     void put(long long x, long long k) {       for (int i = x + 1; i < N; i += -i & i) d[i] ^= k;       for (int i = x + 1; (x & 1) && i < N; i += -i & i) t[i] ^= k;     }     long long ask(long long x, long long lrv = 0, long long rrv = 0) {       for (int i = x + 1; i; i -= -i & i) lrv ^= d[i];       for (int i = x + 1; i; i -= -i & i) rrv ^= t[i];       return (x + 1 & 1) * lrv ^ rrv;     }   };   struct ft2_t {     ft_t d[N], t[N];     void init() {       for (int i = 0; i < N; i++) {         d[i].init();         t[i].init();       }     }     void put(long long x, long long y, long long k) {       for (int i = x + 1; i < N; i += -i & i) d[i].put(y, k);       for (int i = x + 1; (x & 1) && i < N; i += -i & i) t[i].put(y, k);     }     long long ask(long long x, long long y, long long lrv = 0,                   long long rrv = 0) {       for (int i = x + 1; i; i -= -i & i) lrv ^= d[i].ask(y);       for (int i = x + 1; i; i -= -i & i) rrv ^= t[i].ask(y);       return (x + 1 & 1) * lrv ^ rrv;     }     void draw(long long x0, long long y0, long long x1, long long y1,               long long k) {       put(x0, y0, k), put(x1 + 1, y0, k), put(x0, y1 + 1, k),           put(x1 + 1, y1 + 1, k);     }     long long pick(long long x0, long long y0, long long x1, long long y1) {       return ask(x1, y1) ^ ask(x0 - 1, y1) ^ ask(x1, y0 - 1) ^              ask(x0 - 1, y0 - 1);     }   };   int n, m;   ft2_t zkl;   int main() {     for (; ~scanf( %d%d , &n, &m);) {       zkl.init();       for (int op, x0, y0, x1, y1; m--;) {         scanf( %d%d%d%d%d , &op, &x0, &y0, &x1, &y1);         if (op == 1) {           cout << zkl.pick(x0, y0, x1, y1) << endl;         } else {           long long k;           scanf( %lld , &k);           zkl.draw(x0, y0, x1, y1, k);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<pair<int, int> > vneg, vpos;     int n, a, b, neg = 0, pos = 0, sum = 0, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       if (a < 0) {         neg++;         vneg.push_back({a, b});       } else {         pos++;         vpos.push_back({a, b});       }       sum += b;     }     sort(vneg.begin(), vneg.end());     sort(vpos.begin(), vpos.end());     if (neg == 0) {       cout << vpos[0].second << endl;       return 0;     } else if (pos == 0) {       cout << vneg[vneg.size() - 1].second << endl;       return 0;     }     int mn = min(vneg.size(), vpos.size());     int i, j;     for (i = vneg.size() - 1, j = 0; j < mn; i--, j++) {       ans = ans + vneg[i].second + vpos[j].second;     }     if (vneg.size() > vpos.size()) ans += vneg[i].second;     if (vneg.size() < vpos.size()) ans += vpos[j].second;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, M;     scanf( %d %d , &N, &M);     int beat[N + 5], i;     memset(beat, 0, sizeof(beat));     set<int> S;     for (int i = 1; i <= N; i++) S.insert(i);     int L, R, W;     set<int>::iterator it;     while (M--) {       scanf( %d %d %d , &L, &R, &W);       set<int>::iterator lt = S.lower_bound(L);       set<int>::iterator rt = S.upper_bound(R);       for (it = lt; it != rt; it++) {         int val = *it;         if (val != W) beat[val] = W;       }       S.erase(lt, rt);       S.insert(W);     }     for (int i = 1; i <= N - 1; i++) printf( %d  , beat[i]);     printf( %d n , beat[N]);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   const int MAXN = 7200;   const int INF = 0x3f3f3f3f;   bool vis[MAXN];   char s[55][55];   struct Edge {     int x, y, z, nxt;   } e[MAXN << 1];   int dx[5] = {0, 0, 1, -1};   int dy[5] = {1, -1, 0, 0};   int n, m, cnt, tot, ans = INF, head[MAXN], dis[MAXN], NUM[55][55];   inline void add_edge(int x, int y, int z) {     e[++cnt].x = x, e[cnt].y = y, e[cnt].z = z;     e[cnt].nxt = head[x], head[x] = cnt;   }   inline void spfa(int nowx) {     for (register int i = 1; i <= tot; i++) dis[i] = INF, vis[i] = false;     std::queue<int> q;     dis[nowx] = 1, vis[nowx] = true, q.push(nowx);     while (!q.empty()) {       int x = q.front();       q.pop();       for (register int i = head[x]; i; i = e[i].nxt) {         int to = e[i].y;         if (dis[to] > dis[x] + e[i].z) {           dis[to] = dis[x] + e[i].z;           if (!vis[to]) q.push(to), vis[to] = true;         }       }       vis[x] = false;     }     int res = 0;     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= m; j++)         if (s[i][j] ==  B ) res = std::max(res, dis[NUM[i][j]]);     ans = std::min(ans, res);   }   signed main() {     scanf( %d %d , &n, &m);     for (register int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= m; j++) NUM[i][j] = ++tot;     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         for (register int k = 0; k < 4; k++) {           int nowx = i + dx[k], nowy = j + dy[k];           nowx = i + dx[k], nowy = j + dy[k];           if (nowx < 1 or nowx > n or nowy < 1 or nowy > m) continue;           if (s[i][j] == s[nowx][nowy]) add_edge(NUM[i][j], NUM[nowx][nowy], 0);           if (s[i][j] != s[nowx][nowy]) add_edge(NUM[i][j], NUM[nowx][nowy], 1);         }       }     }     for (register int i = 1; i <= tot; i++) spfa(i);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   inline int sgn(int x) {     if (x > -eps || x < eps) return 0;     if (x > 0)       return 1;     else       return -1;   }   struct point {     double x, y;     point(double a = 0, double b = 0) {       x = a;       y = b;     }     point operator+(const point &b) const { return point(x + b.x, y + b.y); }     point operator-(const point &b) const { return point(x - b.x, y - b.y); }     point operator*(const double &t) const { return point(x * t, y * t); }   };   struct circle {     point o;     double r;   };   inline double sqr(double x) { return x * x; }   inline double det(const point &a, const point &b) {     return a.x * b.y - b.x * a.y;   }   inline double dist(const point &a, const point &b) {     return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));   }   inline double mysqrt(double x) { return sqrt(max(0.0, x)); }   inline circle inversion(circle a, point p, double R) {     circle res;     double d1 = dist(p, a.o);     res.r = a.r * R * R / (sqr(d1) - sqr(a.r));     double d2 = R * R / (d1 - a.r) - res.r;     res.o = p + (a.o - p) * (d2 / d1);     return res;   }   circle a, b;   int k;   double R, r, ans;   inline void prework() { scanf( %lf%lf%d , &R, &r, &k); }   inline void mainwork() {     double lx = R * 2, rx = sqr(R * 2) / (2 * r);     a.o = point(2 * r + (R - r), 0);     a.r = R - r;     a = inversion(a, point(0, 0), 2 * R);     b.o = point(a.o.x, a.o.y + k * (rx - lx));     b.r = (rx - lx) / 2;     b = inversion(b, point(0, 0), 2 * R);     ans = b.r;   }   inline void print() { printf( %.8f n , ans); }   int main() {     int t;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       prework();       mainwork();       print();     }     return 0;   }
#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int N = 1010;   const int inf = 0x3f3f3f3f;   using namespace std;   long long sum[N];   int n, a[N], b[N], v, e;   int p[N];   int find(int x) {     if (p[x] != x) p[x] = find(p[x]);     return p[x];   }   vector<int> vt[N];   bool vis[N];   struct Data {     int a, b, c;   };   Data que[N * N];   int head;   bool dfs(int from, int to, int cap) {     if (from == to) return 1;     vis[from] = 1;     for (int i = 0; i < vt[from].size(); i++) {       int t = vt[from][i];       if (vis[t]) continue;       if (a[t] < cap) {         int tmp = cap - a[t];         a[from] -= cap - a[t];         a[t] += tmp;         que[head++] = (Data{from, t, tmp});         if (dfs(t, to, cap) == 0) {           a[from] += tmp;           a[t] -= tmp;           head--;           continue;         }         a[from] -= cap - tmp;         a[t] += cap - tmp;         que[head++] = (Data{from, t, cap - tmp});       } else {         if (dfs(t, to, cap) == 0) continue;         a[from] -= cap;         a[t] += cap;         que[head++] = (Data{from, t, cap});       }       return 1;     }     return 0;   }   int main() {     queue<int> quea[N], queb[N];     scanf( %d%d%d , &n, &v, &e);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       p[i] = i;     }     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= e; i++) {       int x, y;       scanf( %d%d , &x, &y);       vt[x].push_back(y);       vt[y].push_back(x);       p[find(x)] = find(y);     }     for (int i = 1; i <= n; i++) {       int x = find(i);       sum[x] += a[i] - b[i];       if (a[i] > b[i]) quea[x].push(i);       if (b[i] > a[i]) queb[x].push(i);     }     for (int i = 1; i <= n; i++)       if (sum[i]) return puts( NO ), 0;     for (int i = 1; i <= n; i++) {       if (find(i) != i) continue;       while (quea[i].size()) {         memset(vis, 0, sizeof(vis));         int x = quea[i].front();         int y = queb[i].front();         if (a[x] - b[x] > b[y] - a[y]) {           dfs(x, y, b[y] - a[y]);           queb[i].pop();         } else if (a[x] - b[x] < b[y] - a[y]) {           dfs(x, y, a[x] - b[x]);           quea[i].pop();         } else {           dfs(x, y, a[x] - b[x]);           quea[i].pop();           queb[i].pop();         }       }     }     cout << head << endl;     for (int i = 0; i < head; i++) {       Data da = que[i];       cout << da.a <<     << da.b <<     << da.c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long c[110], k;   int n, a[110];   int main() {     c[0] = c[1] = 1LL;     for (int i = 2; i < 100; i++) c[i] = c[i - 1] + c[i - 2];     scanf( %d%I64d , &n, &k);     for (int i = 1; i <= n;) {       if (k > c[n - i]) {         k -= c[n - i];         a[i] = i + 1;         a[i + 1] = i;         i += 2;       } else {         a[i] = i;         i++;       }     }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s, t;   int psum[100005];   vector<int> pos[2][2];   int cost[100005];   long long dp[100005];   int chosen[100005];   int mx;   bool ok(int c) {     dp[0] = 0;     chosen[0] = 0;     for (int i = (1); i <= (s); i += (1)) {       dp[i] = dp[i - 1];       chosen[i] = chosen[i - 1];       if (cost[i] < 1000000000 && i >= t) {         long long nc = dp[i - t] + cost[i] - c;         if (nc < dp[i] || (nc == dp[i] && chosen[i - t] + 1 > chosen[i])) {           dp[i] = nc;           chosen[i] = chosen[i - t] + 1;         }       }     }     return (chosen[s] >= mx);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string S;     cin >> s >> S >> t;     for (int i = (1); i <= (s); i += (1)) {       psum[i] = psum[i - 1] + (S[i - 1] ==  ? );       if (S[i - 1] !=  ? ) pos[S[i - 1] -  a ][i & 1].push_back(i);     }     for (int i = (1); i <= (s - t + 1); i += (1)) {       auto &v = pos[0][~i & 1];       int p = lower_bound(v.begin(), v.end(), i) - v.begin();       auto &v2 = pos[1][i & 1];       int q = lower_bound(v2.begin(), v2.end(), i) - v2.begin();       int ed = i + t - 1;       if ((p != v.size() && v[p] <= ed) || (q != v2.size() && v2[q] <= ed))         cost[ed] = 1000000000;       else         cost[ed] = psum[ed] - psum[i - 1];     }     chosen[0] = 0;     for (int i = (1); i <= (s); i += (1)) {       chosen[i] = chosen[i - 1];       if (i >= t && cost[i] < 1000000000)         chosen[i] = max(chosen[i], chosen[i - t] + 1);     }     mx = chosen[s];     int l = 0, r = t;     while (l <= r) {       int m = (l + r) >> 1;       if (ok(m))         r = m - 1;       else         l = m + 1;     }     ok(t + 5);     printf( %lld n , dp[s] + 1LL * (t + 5) * mx);     return 0;   }