malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int get(char *s) {     if (s[0] ==  8  && s[1] ==  < ) return 1;     if (s[0] ==  [  && s[1] ==  ] ) return 2;     if (s[0] ==  (  && s[1] ==  ) ) return 3;   }   int check(int a, int b) {     if (a == 1 && b == 2 || a == 2 && b == 3 || a == 3 && b == 1) return 1;     if (a == 2 && b == 1 || a == 3 && b == 2 || a == 1 && b == 3) return 2;     return 0;   }   int main() {     char a[100] = {0}, b[100] = {0};     scanf( %s , a);     scanf( %s , b);     int x = 0, y = 0;     for (int i = 0; i < strlen(a); i += 2) {       int t = check(get(a + i), get(b + i));       if (t == 1) x++;       if (t == 2) y++;     }     if (x == y)       printf( TIE );     else if (x < y)       printf( TEAM 2 WINS );     else       printf( TEAM 1 WINS );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int nn, i, j, k;     cin >> nn;     long long int a[nn];     for (i = 0; i < nn; i++) cin >> a[i];     sort(a, a + nn);     for (i = 0; i < nn; i++) {       for (j = i + 1; j < nn; j++) {         if (a[i] != -1 && a[j] != -1 && a[j] % a[i] == 0) a[j] = -1;       }     }     long long int sum = 0;     for (i = 0; i < nn; i++) {       if (a[i] != -1) sum++;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   long long ara[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long mx = 0;     for (long long i = 0; i < n; ++i) {       cin >> ara[i];       while (ara[i] % 2 == 0) ara[i] /= 2;       while (ara[i] % 3 == 0) ara[i] /= 3;     }     for (long long i = 1; i < n; ++i) {       if (ara[i] != ara[0]) return cout <<  No , 0;     }     cout <<  Yes ;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 100005;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;       cin >> n;       vector<long long int> v;       cout << n <<    ;       i = n - 1;       while (i > 0) {         if (n % i == 0) {           cout << i <<    ;           n = i;           i = n - 1;         } else {           i--;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int i;       int a[n];       int even = 0, odd = 0;       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] % 2 == 0)           even++;         else           odd++;       }       if (even % 2 == 0 && odd % 2 == 0) {         cout <<  YES  << endl;         continue;       }       sort(a, a + n, less<int>());       for (i = 1; i < n; i++) {         int k = 1;         while (a[i - k] == 0 && (i - k) > 0) {           k++;         }         if (a[i] - a[i - k] == 1) {           a[i] = 0;           a[i - k] = 0;           even--;           odd--;           if (even % 2 == 0 && odd % 2 == 0) {             cout <<  YES  << endl;             break;           }         }       }       if (i == n) cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[100005];   long long ans = 0;   long long temp[100005];   bool is(int m, string s) {     set<char> ss;     map<char, int> mp;     for (int i = 0; i < m; i++) {       ss.insert(s[i]);       mp[s[i]]++;     }     if (ss.size() == ans) return true;     for (int i = 0; i <= s.length() - m - 1; i++) {       mp[s[i]]--;       if (mp[s[i]] == 0) ss.erase(s[i]);       ss.insert(s[i + m]);       mp[s[i + m]]++;       if (ss.size() == ans) {         return true;       }     }     return false;   }   int main() {     int n;     string s;     cin >> n >> s;     set<char> se;     for (char c : s) se.insert(c);     ans = se.size();     int l = 0;     int r = n + 1;     while (r - l > 1) {       int m = l + (r - l) / 2;       if (!is(m, s))         l = m;       else         r = m;     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int MOD = 1000000007;   int d, n;   int a[N];   int ord[N], rnk[N];   vector<int> v[N];   inline bool cmp(int x, int y) { return a[x] > a[y]; }   int ans = 0;   int sz[N];   inline void dfs(int x, int top) {     sz[x] = 1;     for (int i = 0; i < v[x].size(); i++) {       int next = v[x][i];       if (sz[next] || rnk[next] < rnk[top] || a[top] - a[next] > d) continue;       dfs(next, top);       sz[x] = (long long)sz[x] * (sz[next] + 1) % MOD;     }   }   int main() {     scanf( %d%d , &d, &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ord[i] = i;     sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; i++) rnk[ord[i]] = i;     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       memset(sz, 0, sizeof(sz));       dfs(ord[i], ord[i]);       ans = (ans + sz[ord[i]]) % MOD;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <typename T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <typename T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void println(T first) {     print(first), putchar(  n );   }   template <typename T>   inline void printsp(T first) {     print(first), putchar(   );   }   template <class T, class T1>   inline void print(T first, T1 second) {     printsp(first), println(second);   }   template <class T, class T1, class T2>   inline void print(T first, T1 second, T2 z) {     printsp(first), printsp(second), println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = (long long)a * a % m)       if (b & 1) ans = (long long)ans * a % m;     return ans;   }   pair<int, int> p[50010];   int f[50010];   void go(int first) {     printf( ? %d n , first);     fflush(stdout);     gn(p[first].first, p[first].second);   }   void end(int first) {     printf( ! %d n , first);     exit(0);   }   int main() {     int n, id, first;     gn(n, id, first);     for (int i = 1; i <= n; i++) f[i] = i;     srand(time(0));     random_shuffle(f + 1, f + n + 1);     go(id);     if (p[id].first >= first) end(p[id].first);     int N = min(n, 1000);     for (int i = 1; i <= N; i++) {       go(f[i]);       int u = p[f[i]].first;       if (u < first && u > p[id].first) id = f[i];     }     while (1) {       if (!p[id].second) go(id);       if (p[id].first >= first) end(p[id].first);       if (p[id].second == -1) end(-1);       id = p[id].second;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   vector<pair<int, int>> g[N], ans[N];   long long dist[N];   priority_queue<pair<int, int>> pq;   bool vis[N];   void dijkstra(int s) {     fill(dist, dist + N, 1LL << 61);     memset(vis, false, sizeof(vis));     dist[s] = 0;     pq.push({0, s});     while (!pq.empty()) {       int u = pq.top().second;       pq.pop();       if (vis[u]) continue;       vis[u] = true;       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i].first, w = g[u][i].second;         if (dist[v] > dist[u] + w) {           dist[v] = dist[u] + w;           pq.push({-dist[v], v});         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     int x, y;     cin >> x >> y;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     for (int i = 1; i <= n; i++) {       long long ti, ci;       cin >> ti >> ci;       dijkstra(i);       for (int j = 1; j <= n; j++) {         if (dist[j] <= ti) {           ans[i].push_back({j, ci});         }       }     }     for (int i = 1; i <= n; i++) {       g[i] = ans[i];     }     dijkstra(x);     if (dist[y] == 1LL << 61)       cout << -1;     else       cout << dist[y];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const long long mod = (long long)1e9 + 7;   const double eps = (double)1e-9;   const double pi = acos(-1.0);   const int dx[] = {0, 0, 1, 0, -1};   const int dy[] = {0, 1, 0, -1, 0};   const int N = 300500;   int n, l[N], r[N], a[N], ans, c;   int main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       cin >> n;       for (int i = 1; i <= n; ++i) l[i] = 0, r[i] = n;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         if (l[a[i]] == 0) l[a[i]] = i;         r[a[i]] = i;       }       sort(a + 1, a + n + 1);       ans = 1, c = 0;       int m = 1;       for (int i = 2; i <= n; ++i) {         if (a[i] == a[i - 1]) continue;         m++;         if (r[a[i - 1]] < l[a[i]])           c++;         else           c = 0;         ans = max(ans, c + 1);       }       cout << m - ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int G = 3;   const int MOD = 998244353;   const int N = (1 << 15) + 5;   int rev[N], w[N], inv_n;   int bigMod(int a, int e, int mod) {     if (e == -1) e = mod - 2;     int ret = 1;     while (e) {       if (e & 1) ret = (long long)ret * a % mod;       a = (long long)a * a % mod;       e >>= 1;     }     return ret;   }   void prepare(int &n) {     int sz = abs(31 - __builtin_clz(n));     int r = bigMod(G, (MOD - 1) / n, MOD);     inv_n = bigMod(n, MOD - 2, MOD), w[0] = w[n] = 1;     for (int i = 1; i < n; ++i) w[i] = (long long)w[i - 1] * r % MOD;     for (int i = 1; i < n; ++i)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (sz - 1));   }   void ntt(int *a, int n, int dir) {     for (int i = 1; i < n - 1; ++i) {       if (i < rev[i]) swap(a[i], a[rev[i]]);     }     for (int m = 2; m <= n; m <<= 1) {       for (int i = 0; i < n; i += m) {         for (int j = 0; j < (m >> 1); ++j) {           int &u = a[i + j], &v = a[i + j + (m >> 1)];           int t = (long long)v * w[dir ? n - n / m * j : n / m * j] % MOD;           v = u - t < 0 ? u - t + MOD : u - t;           u = u + t >= MOD ? u + t - MOD : u + t;         }       }     }     if (dir)       for (int i = 0; i < n; ++i) a[i] = (long long)a[i] * inv_n % MOD;   }   int f_a[N], f_b[N];   vector<long long> multiply(vector<long long> a, vector<long long> b) {     int sz = 1, n = a.size(), m = b.size();     while (sz < n + m - 1) sz <<= 1;     prepare(sz);     for (int i = 0; i < sz; ++i) f_a[i] = i < n ? a[i] : 0;     for (int i = 0; i < sz; ++i) f_b[i] = i < m ? b[i] : 0;     ntt(f_a, sz, 0);     ntt(f_b, sz, 0);     for (int i = 0; i < sz; ++i) f_a[i] = (long long)f_a[i] * f_b[i] % MOD;     ntt(f_a, sz, 1);     return vector<long long>(f_a, f_a + n + m - 1);   }   int n, k, q;   long long a[N], b[N];   vector<long long> get(int lo, int hi) {     if (lo == hi) return {b[lo], 1};     int mid = lo + hi >> 1;     vector<long long> one = get(lo, mid);     vector<long long> two = get(mid + 1, hi);     return multiply(one, two);   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) scanf( %lld , a + i);     cin >> q;     while (q--) {       long long cmd, x, l, r, p;       scanf( %lld %lld %lld %lld , &cmd, &x, &l, &r);       if (cmd == 1) {         for (int i = 1; i <= n; ++i) {           b[i] = a[i];           if (i == l) b[i] = r;         }       } else {         scanf( %lld , &p);         for (int i = 1; i <= n; ++i) {           b[i] = a[i];           if (l <= i and i <= r) b[i] += p;         }       }       for (int i = 1; i <= n; ++i) {         b[i] = x - b[i], b[i] %= MOD;         if (b[i] < 0) b[i] += MOD;       }       vector<long long> yo = get(1, n);       printf( %lld n , yo[n - k]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[100003];   int n;   int main() {     int i;     scanf( %d , &n);     if (n == 1) {       printf( 1 n );       return 0;     }     if (n == 2) {       printf( -1 n );       return 0;     }     if (n % 2 != 0) p[n / 2 + 1] = n / 2 + 1;     p[1] = 2;     p[2] = n;     p[n] = n - 1;     p[n - 1] = 1;     for (i = 3; i < n / 2 + 1; i++) {       if (i % 2 != 0)         p[i] = p[i - 2] + 2;       else         p[i] = p[i - 2] - 2;     }     int coun = 0;     if (n % 2 == 0) {       for (i = n - 2; i > n / 2; i--) {         if (coun % 2 == 0)           p[i] = p[i + 2] - 2;         else           p[i] = p[i + 2] + 2;         coun++;       }     } else {       for (i = n - 2; i > n / 2 + 1; i--) {         if (coun % 2 == 0)           p[i] = p[i + 2] - 2;         else           p[i] = p[i + 2] + 2;         coun++;       }     }     bool fl = true;     for (i = 1; i <= n; i++)       if (p[p[i]] != n - i + 1) fl = false;     if (fl) {       printf( %d , p[1]);       for (i = 2; i <= n; i++) printf(  %d , p[i]);       printf(  n );     } else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void use_cio() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   template <typename... Args>   void dbg(Args... args) {     ((cout << args <<    ), ...);     cout << endl;   }   int n;   int ask(int r1, int c1, int r2, int c2) {     string ans;     dbg( ? , r1, c1, r2, c2);     cout.flush();     cin >> ans;     return (ans ==  YES );   }   int main() {     cin >> n;     string l, r;     int sx = 1, sy = 1;     while (sx + sy < n + 1) {       if (sy + 1 <= n && ask(sx, sy + 1, n, n)) {         sy++;         l +=  R ;       } else {         sx++;         l +=  D ;       }     }     int ex = n, ey = n;     while (ex + ey > n + 1) {       if (ex && ask(1, 1, ex - 1, ey)) {         ex--;         r +=  D ;       } else {         ey--;         r +=  R ;       }     }     reverse(r.begin(), r.end());     dbg( ! , l + r);   }
#include <bits/stdc++.h>   using namespace std;   long long dp[15][1 << 15];   int n, m, q;   struct NodeLCA {     int a, b, c;   };   vector<pair<int, int> > path;   vector<NodeLCA> LCA;   void readData() {     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       path.push_back(make_pair(u, v));     }     for (int i = 0; i < q; i++) {       int u, v, w;       cin >> u >> v >> w;       u--;       v--;       w--;       LCA.push_back({u, v, w});     }   }   int check(int root, int mask1, int child, int mask2) {     for (int i = 0; i < path.size(); i++) {       if (!(mask1 & (1 << path[i].first)) || !(mask1 & (1 << path[i].second)))         continue;       if (((mask2 & (1 << path[i].first)) > 0) ==           ((mask2 & (1 << path[i].second)) > 0))         continue;       if (path[i].second == root) swap(path[i].first, path[i].second);       if ((path[i].first != root) || (path[i].second != child)) return 0;     }     for (int i = 0; i < LCA.size(); i++) {       if (!(mask1 & (1 << LCA[i].a)) || !(mask1 & (1 << LCA[i].b))) continue;       if (((mask2 & (1 << LCA[i].a)) > 0) == ((mask2 & (1 << LCA[i].b)) > 0))         continue;       if (LCA[i].c != root) return 0;     }     return 1;   }   void dynamicProgramming() {     int mask, submask;     for (int i = 0; i < n; i++) dp[i][1 << i] = 1;     for (mask = 1; mask < (1 << n); mask++)       for (int i = 0; i < n; i++)         if (mask & (1 << i)) {           int tmp = -1;           for (int t = 0; t < n; t++)             if (t != i && (mask & (1 << t))) tmp = t;           if (tmp == -1) continue;           for (submask = (mask - 1) & mask; submask > 0;                submask = (submask - 1) & mask)             if ((submask & (1 << tmp)) && !(submask & (1 << i)))               for (int child = 0; child < n; child++)                 if (submask & (1 << child)) {                   if (check(i, mask, child, submask))                     dp[i][mask] += dp[child][submask] * dp[i][mask - submask];                 }         }   }   void writeData() { cout << dp[0][(1 << n) - 1]; }   int main() {     readData();     for (int i = 0; i < LCA.size(); i++)       if (LCA[i].a == LCA[i].b && LCA[i].a != LCA[i].c) {         cout << 0;         return 0;       }     dynamicProgramming();     writeData();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m, k, count = 0;     cin >> n >> m >> k;     long long int s = n * m;     long long int a[s], b[s];     for (long long int i = 0; i < s; i++) cin >> a[i];     sort(a, a + s);     for (long long int i = 0; i < s; i++) {       b[i] = abs(a[i] - a[s / 2]);       if (b[i] % k != 0) {         cout << -1;         return 0;       } else {         count += b[i] / k;       }     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, k;   int arr[N];   int a, b;   vector<int> v[N];   int tmp[N];   int subtree1[N];   int subtree2[N];   int sum[N];   int bst1[N];   int bst2[N];   bool ret;   void dfs(int node, int parent) {     subtree1[node] = 1;     subtree2[node] = tmp[node];     for (int next : v[node]) {       if (next != parent) {         dfs(next, node);         subtree1[node] += subtree1[next];         subtree2[node] += subtree2[next];       }     }   }   void dfs1(int node, int parent) {     sum[node] = 0;     bst1[node] = 0;     bst2[node] = 0;     for (int next : v[node]) {       if (next != parent) {         dfs1(next, node);         if (subtree2[next] == subtree1[next]) {           sum[node] += subtree1[next];         } else {           if (sum[next] > bst1[node]) {             bst2[node] = bst1[node];             bst1[node] = sum[next];           } else if (sum[next] > bst2[node]) {             bst2[node] = sum[next];           }         }       }     }     if (tmp[node]) {       ++sum[node];       sum[node] += bst1[node];     } else {       sum[node] = 0;       bst1[node] = 0;       bst2[node] = 0;     }     ret |= (sum[node] >= k);   }   void dfs2(int node, int parent, int val) {     if (val == n - subtree1[node]) {       sum[node] += val;     } else {       sum[node] -= bst1[node];       if (val > bst1[node]) {         bst2[node] = bst1[node];         bst1[node] = val;       } else if (val > bst2[node]) {         bst2[node] = val;       }       sum[node] += bst1[node];     }     if (!tmp[node]) {       sum[node] = 0;       bst1[node] = 0;       bst2[node] = 0;     }     ret |= (sum[node] >= k);     for (int next : v[node]) {       if (next != parent) {         if (subtree1[next] == subtree2[next]) {           dfs2(next, node, sum[node] - subtree1[next]);         } else if (bst1[node] == sum[next]) {           dfs2(next, node, sum[node] - bst1[node] + bst2[node]);         } else {           dfs2(next, node, sum[node]);         }       }     }   }   bool check(int val) {     for (int i = 1; i <= n; ++i) {       tmp[i] = (arr[i] >= val);     }     ret = 0;     dfs(1, 0);     dfs1(1, 0);     if (ret) {       return 1;     }     dfs2(1, 0, 0);     return ret;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , arr + i);     }     for (int i = 1; i < n; ++i) {       scanf( %d %d , &a, &b);       v[a].emplace_back(b);       v[b].emplace_back(a);     }     int l = 1;     int r = 1e6 + 1;     while (l < r) {       int mid = l + r >> 1;       if (check(mid)) {         l = mid + 1;       } else {         r = mid;       }     }     printf( %d n , l - 1);   }
#include <bits/stdc++.h>   using namespace std;   struct Bus {     long long s, t;   };   bool cmp(Bus &a, Bus &b) { return a.t < b.t; }   long long n, m, it[4 * 111111], tmp = 1, l, r;   Bus bus[111111];   vector<long long> positions;   void update(int idx, int l, int r, int pos, long long val) {     if (pos < l || pos > r) return;     if (l == r) {       it[idx] = val;       return;     }     int m = (l + r) / 2;     update(2 * idx, l, m, pos, val);     update(2 * idx + 1, m + 1, r, pos, val);     it[idx] = (it[2 * idx] + it[2 * idx + 1]) % 1000000007;   }   long long get(int idx, int l, int r, int u, int v) {     if (v < l || r < u) return 0;     if (u <= l && r <= v) return it[idx];     int m = (l + r) / 2;     long long ret =         (get(2 * idx, l, m, u, v) + get(2 * idx + 1, m + 1, r, u, v)) %         1000000007;     return ret;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> bus[i].s >> bus[i].t;     sort(bus, bus + m, cmp);     positions.push_back(0);     for (int i = 0; i < m; i++)       if (bus[i].t != positions[positions.size() - 1])         positions.push_back(bus[i].t);     if (n != positions[positions.size() - 1]) positions.push_back(n);     update(1, 0, positions.size() - 1, 0, 1);     for (int i = 0; i < m; i++) {       l = lower_bound(positions.begin(), positions.end(), bus[i].s) -           positions.begin();       r = upper_bound(positions.begin(), positions.end(), bus[i].t) -           positions.begin() - 1;       tmp = get(1, 0, positions.size() - 1, l, r);       update(1, 0, positions.size() - 1, r, tmp);     }     cout << get(1, 0, positions.size() - 1, positions.size() - 1,                 positions.size() - 1);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, k;   string s;   bool can_del(char c) {     int l = N, r = -1;     for (int i = 0; i < n; ++i) {       if (s[i] == c) {         l = min(l, i);         r = max(r, i);       }     }     return r - l + 1 <= k;   }   string ans1 =  tokitsukaze , ans2 =  quailty , ans3 =  once again ;   bool win(string s) { return can_del( 0 ) || can_del( 1 ); }   vector<int> pos[2];   int ml[2], mr[2];   void f(int l, int r, int t) {     if (pos[t].size() && pos[t][0] < l) ml[t] = min(ml[t], pos[t][0]);     auto p = upper_bound(pos[t].begin(), pos[t].end(), r);     if (p != pos[t].end()) {       ml[t] = min(ml[t], *p);     }     if (pos[t].size() && pos[t].back() > r) mr[t] = max(mr[t], pos[t].back());     p = lower_bound(pos[t].begin(), pos[t].end(), l);     if (p != pos[t].begin()) {       --p;       mr[t] = max(mr[t], *p);     }   }   bool col(int l, int r, int t) {     for (int i = 0; i < 2; ++i) {       ml[i] = N;       mr[i] = -1;     }     ml[t] = l;     mr[t] = r;     f(l, r, 0);     f(l, r, 1);     for (int i = 0; i < 2; ++i) {       if (mr[i] - ml[i] + 1 <= k) {         return 0;       }     }     return 1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> s;     for (int i = 0; i < n; ++i) {       pos[s[i] -  0 ].push_back(i);     }     if (win(s)) {       cout << ans1 <<   n ;       exit(0);     }     for (int i = 0; i + k - 1 < n; ++i) {       if (col(i, i + k - 1, 0)) {         cout << ans3 <<   n ;         exit(0);       }       if (col(i, i + k - 1, 1)) {         cout << ans3 <<   n ;         exit(0);       }     }     cout << ans2 <<   n ;   }