malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, k, a[3000000];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     int mini = 2000000;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       mini = min(mini, x);       a[max(1, x - k)]++;       a[x + 1]--;     }     for (int i = 1; i <= 1500000; i++) a[i] += a[i - 1];     for (int i = 1000000; i >= k + 1; i--) {       int sum = 0;       for (int j = 0; j <= 1000000; j += i) sum += a[j];       assert(sum <= n);       if (sum == n) {         cout << i << endl;         return 0;       }     }     cout << mini << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3000000;   const int MAXM = 200000;   const int INF = 1000000010;   const long long int MOD = 1000000007;   const long long int P = 31;   const long double EPS = 1e-6;   int N, M, K;   char s[MAXN];   long long int dp[26] = {0};   int last_used[26];   int main() {     ios_base::sync_with_stdio(false);     scanf( %d %d , &M, &K);     scanf( %s , s);     N = strlen(s);     memset(last_used, -1, sizeof(last_used));     long long int tmp;     for (int i = 0; i < N; i++) {       tmp = 1;       for (int j = 0; j < K; j++) {         tmp = (tmp + dp[j]) % MOD;       }       dp[s[i] -  a ] = tmp;       last_used[s[i] -  a ] = i;     }     int ptr;     for (int i = 0; i < M; i++) {       ptr = 0;       tmp = 1;       for (int j = 0; j < K; j++) {         tmp = (tmp + dp[j]) % MOD;         if (last_used[j] < last_used[ptr]) ptr = j;       }       dp[ptr] = tmp;       last_used[ptr] = i + N;     }     tmp = 1;     for (int i = 0; i < K; i++) tmp = (tmp + dp[i]) % MOD;     printf( %I64d , tmp);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 1000000000000001000LL;   const int mod = 1000000007;   const int MAXN = 300010, LOG = 19;   struct Data {     long long w[2][2];   } SP[MAXN][LOG];   Data operator+(Data x, Data y) {     Data out;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         out.w[i][j] = min(x.w[i][0] + y.w[0][j], x.w[i][1] + y.w[1][j]);     return out;   }   long long n, m, k, u, v, x, y, t, a, b;   long long W[MAXN][2];   int h[MAXN];   int par[MAXN][LOG];   Data D[MAXN];   long long dist[MAXN];   bool mark[MAXN];   vector<pair<int, int>> G[MAXN];   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                  greater<pair<long long, long long>>>       pq;   void dfs(int node) {     for (int i = 1; i < LOG; i++) {       par[node][i] = par[par[node][i - 1]][i - 1];       SP[node][i] = SP[node][i - 1] + SP[par[node][i - 1]][i - 1];     }     h[node] = h[par[node][0]] + 1;     for (pair<int, int> p : G[node])       if (p.first != par[node][0]) {         int v = p.first, i = p.second;         par[v][0] = node;         SP[v][0].w[0][0] = min(W[i][0], W[i][1] + dist[v] + dist[node]);         SP[v][0].w[1][1] = min(W[i][1], W[i][0] + dist[v] + dist[node]);         SP[v][0].w[0][1] = min(W[i][0] + dist[node], dist[v] + W[i][1]);         SP[v][0].w[1][0] = min(W[i][1] + dist[node], dist[v] + W[i][0]);         dfs(v);       }   }   int LCA(int x, int y) {     if (h[x] > h[y]) swap(x, y);     for (int i = 0; i < LOG; i++)       if ((h[y] - h[x]) & (1 << i)) y = par[y][i];     if (x == y) return x;     for (int i = LOG - 1; i >= 0; i--)       if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];     return par[x][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> x, pq.push({dist[i] = x, i});     for (int i = 1; i < n; i++) {       cin >> u >> v >> W[i][1] >> W[i][0];       G[u].push_back({v, i});       G[v].push_back({u, i});     }     while (!pq.empty()) {       int v = pq.top().second;       pq.pop();       if (mark[v]) continue;       mark[v] = 1;       for (pair<int, int> p : G[v])         if (!mark[p.first]) {           long long w = W[p.second][0] + W[p.second][1];           if (dist[v] + w < dist[p.first])             pq.push({dist[p.first] = dist[v] + w, p.first});         }     }     for (int i = 1; i <= n; i++) D[i].w[0][1] = D[i].w[1][0] = dist[i];     dfs(1);     cin >> m;     while (m--) {       cin >> x >> y;       u = (x + 1) / 2;       v = (y + 1) / 2;       int lca = LCA(u, v);       Data ans1 = D[u], ans2 = D[v];       for (int i = 0; i < LOG; i++)         if ((h[lca] - h[u]) & (1 << i)) ans1 = ans1 + SP[u][i], u = par[u][i];       for (int i = 0; i < LOG; i++)         if ((h[lca] - h[v]) & (1 << i)) ans2 = ans2 + SP[v][i], v = par[v][i];       swap(ans2.w[0][1], ans2.w[1][0]);       Data ans = ans1 + ans2;       cout << ans.w[x & 1][y & 1] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     if (n % 2 == 0) return  YES ;     for (int i = 0; i < n - 1; i++)       if (a[i] >= a[i + 1]) return  YES ;     return  NO ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) {       cout << solve() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   void __print(long long int x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename Th, typename V>   void __print(const pair<Th, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename Th>   void __print(const Th &x) {     long long int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename Th, typename... V>   void _print(Th t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void binary_rock() {     string a;     cin >> a;     long long int m;     cin >> m;     long long int i, j, k, l;     vector<long long int> b(m);     for (i = 0; i < m; i++) cin >> b[i];     vector<long long int> fre(26);     for (i = 0; i < 26; i++) fre[i] = 0;     long long int n = a.size();     for (i = 0; i < n; i++) {       fre[a[i] -  a ]++;     };     long long int pos = 25;     string ans =   ;     long long int nikal = 0;     for (i = 0; i < m; i++) ans.push_back(( - ));     ;     ;     while (1) {       long long int zero = 0;       vector<long long int> id;       for (i = 0; i < m; i++) {         if (b[i] == 0) id.push_back(i);       }       zero = id.size();       while (1) {         if (fre[pos] >= zero)           break;         else {           pos--;         }       }       for (i = 0; i < zero; i++) {         ans[id[i]] =  a  + pos;       };       for (i = 0; i < zero; i++) {         long long int x = id[i];         for (j = 0; j < m; j++) {           if (b[j] == 0) continue;           b[j] -= abs(x - j);         }       };       for (i = 0; i < zero; i++) {         b[id[i]] = -1;       }       nikal += zero;       if (nikal >= m) break;       pos--;     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     clock_t t1 = clock();     long long int t = 1;     cin >> t;     while (t--) {       binary_rock();     }     clock_t t2 = clock();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long p[16];   long long Count(long long n, int i) {     long long ret = (i + 1LL) * (n / p[i]);     n %= p[i];     if (n == 0) return ret;     return ret + min(Count(n, i - 1), i + 1 + Count(p[i] - n, i - 1));   }   int main() {     p[0] = 1;     for (int i = 0; i < 16; i++) p[i] = p[i - 1] * 10 + 1;     cin >> n;     cout << Count(n, 15);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[500010];   int main() {     int n;     cin >> n;     a[0] = 2;     vector<pair<int, int> > cumcnt;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (a[i] == a[i - 1])         cumcnt.back().second++;       else         cumcnt.emplace_back(a[i], 1);     }     cumcnt.back().second++;     int N = (int(cumcnt.size()));     int st = 0;     int ans = 0;     for (int i = 0; i < N; i++) {       if (i == N - 1) break;       st += cumcnt[i].second;       int j = i + 1, e = 0;       while (j < N && cumcnt[j].second == 1) j++, e++;       if (j < N) {         int steps = (e + 1) / 2;         ans = max(ans, steps);         for (int make_pair = 0; make_pair < e; ++make_pair) {           if (cumcnt[i].first == cumcnt[j].first)             a[make_pair + st + 1] = cumcnt[i].first;           else {             if (make_pair < e / 2)               a[make_pair + st + 1] = cumcnt[i].first;             else               a[make_pair + st + 1] = cumcnt[j].first;           }         }       }       st += e;       i = j - 1;     }     cout << ans <<   n ;     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    n [i == n];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 7;   vector<vector<int> > g, gr;   vector<char> used;   vector<int> order, component;   void dfs1(int v) {     used[v] = true;     for (size_t i = 0; i < g[v].size(); ++i)       if (!used[g[v][i]]) dfs1(g[v][i]);     order.push_back(v);   }   void dfs2(int v) {     used[v] = true;     component.push_back(v);     for (size_t i = 0; i < gr[v].size(); ++i)       if (!used[gr[v][i]]) dfs2(gr[v][i]);   }   int main() {     int n, cost[MAXN];     cin >> n;     for (int i = 0; i < n; ++i) cin >> cost[i];     int m;     cin >> m;     g.resize(n);     gr.resize(n);     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(b);       gr[b].push_back(a);     }     used.assign(n, false);     for (int i = 0; i < n; ++i)       if (!used[i]) dfs1(i);     used.assign(n, false);     long long ficost = 0;     long long fix = 1;     for (int i = 0; i < n; ++i) {       int v = order[n - 1 - i];       if (!used[v]) {         dfs2(v);         int curmin = INT_MAX;         for (size_t j = 0; j < component.size(); ++j)           curmin = min(curmin, cost[component[j]]);         ficost += curmin;         int curc = 0;         for (size_t j = 0; j < component.size(); ++j)           if (cost[component[j]] == curmin) ++curc;         fix *= curc;         fix %= 1000000000 + 7;         component.clear();       }     }     cout << ficost <<     << fix << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2;   int main() {     cin >> s1 >> s2;     if (s1.length() != s2.length())       cout <<  NO ;     else {       int x = 0;       int y = 0;       for (int i = 0; i < s1.length(); i++) {         if (s1[i] -  0  == 1) x++;         if (s2[i] -  0  == 1) y++;       }       if (x == 0 && y == 0)         cout <<  YES ;       else if (x == 0 && y != 0)         cout <<  NO ;       else if (x != 0 && y == 0)         cout <<  NO ;       else if (x != 0 && y != 0)         cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1E18;   const int MAXN = 2000;   int l[MAXN];   int r[MAXN];   int a[MAXN];   long long dp[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     bool poss = true;     long long extra = 0;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i] >> a[i];       if (i && l[i] > r[i - 1]) extra = 0;       long long bullets = extra + a[i];       if (bullets > (long long)(r[i] - l[i] + 1) * k) {         poss = false;       }       extra = max(0LL, bullets - (long long)(r[i] - l[i]) * k);     }     if (!poss) {       cout <<  -1 n ;       return 0;     }     dp[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; i--) {       dp[i] = INF;       extra = 0;       long long totalUsed = 0;       for (int j = i; j < n; j++) {         totalUsed += a[j];         long long bullets = extra + a[j];         if (bullets > (long long)(r[j] - l[j] + 1) * k) break;         extra = bullets % k;         if (j < n - 1) {           long long last = max(0LL, bullets - (long long)(r[j] - l[j]) * k);           if (r[j] < l[j + 1] || !last) {             if (extra)               dp[i] = min(dp[i], totalUsed + (k - extra) + dp[j + 1]);             else               dp[i] = min(dp[i], totalUsed + dp[j + 1]);           }         } else {           dp[i] = min(dp[i], totalUsed);         }       }     }     cout << dp[0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string n;   int k;   int main() {     cin >> n >> k;     if (n[0] ==  0 ) {       cout << 0 << endl;       return 0;     }     int count = 0, c = 0;     for (int i = n.size() - 1; i >= 0; i--) {       count += (n[i] ==  0 );       c += (n[i] !=  0 );       if (count == k) {         cout << c << endl;         return 0;       }       if (i == 0) {         for (auto m : n)           if (m ==  0 ) {             cout << n.size() - 1 << endl;             return 0;           }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m, tren, pos[N], cnt[N];   vector<int> g[N];   int dist(int a, int tr) {     if (a > tr)       return a - tr;     else       return n + a - tr;   }   bool cmp(int a, int b) {     if (dist(a, tren) < dist(b, tren)) return true;     return false;   }   int next(int i) {     if (i < n) return i + 1;     return 1;   }   int check(int i) {     int num = 0, curr = i, time = 0;     while (num < m) {       if (cnt[curr]) {         num += cnt[curr];         cnt[curr] = 0;       }       if (pos[curr] >= 0) {         cnt[g[curr][pos[curr]]]++;         pos[curr]--;       }       curr = next(curr);       time++;     }     return time - 1;   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);     }     for (int i = 1; i <= n; i++) {       tren = i;       sort(g[i].begin(), g[i].end(), cmp);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cnt[j] = 0;         pos[j] = g[j].size() - 1;       }       printf( %d  , check(i));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int size = 100004;   char s[size][4];   struct node {     int l, r, cnt;     long long sum[6];   } tree[size * 4];   int tmp[size], q[size];   void pushup(int rt) {     int i;     for (i = 0; i < 5; ++i)       tree[rt].sum[i] =           tree[rt << 1].sum[i] +           tree[rt << 1 | 1].sum[(i - tree[rt << 1].cnt % 5 + 5) % 5];     return;   }   void build(int rt, int l, int r) {     int i, mid;     tree[rt].l = l;     tree[rt].r = r;     tree[rt].cnt = 0;     if (l == r) return;     for (i = 0; i < 5; ++i) tree[rt].sum[i] = 0;     mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);   }   void update(int pos, int cnt, int rt, int add) {     tree[rt].cnt += cnt;     if (tree[rt].l == tree[rt].r) {       tree[rt].sum[0] += (long long)add;       return;     } else {       if (pos <= tree[rt << 1].r)         update(pos, cnt, rt << 1, add);       else         update(pos, cnt, rt << 1 | 1, add);       pushup(rt);     }   }   int main() {     int n, cnt, i, j, pos;     while (scanf( %d , &n) != EOF) {       cnt = 0;       for (i = 0; i < n; ++i) {         scanf( %s , s[i]);         if (s[i][0] !=  s ) {           scanf( %d , &q[i]);           tmp[cnt++] = q[i];         }       }       if (cnt > 0) {         sort(tmp, tmp + cnt);         cnt = unique(tmp, tmp + cnt) - tmp;         build(1, 1, cnt);       }       for (i = 0; i < n; ++i) {         if (s[i][0] ==  s ) {           cout << tree[1].sum[2] << endl;         } else {           pos = lower_bound(tmp, tmp + cnt, q[i]) - tmp;           if (s[i][0] ==  a )             update(pos, 1, 1, q[i]);           else             update(pos, -1, 1, -q[i]);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int used[100];   vector<vector<int>> g;   int cmp = 0;   vector<int> parent, rank1;   void make_set(int v) {     parent[v] = v;     rank1[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (rank1[a] < rank1[b]) swap(a, b);       parent[b] = a;       if (rank1[a] == rank1[b]) ++rank1[a];     }   }   bool ok = 1;   void dfs(int v, int p = -1) {     used[v] = 1;     for (auto to : g[v]) {       if (!used[to])         union_sets(v, to), dfs(to, v);       else {         if (to != p) ok = 0;       }     }   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     parent.resize(n);     rank1.resize(n);     for (int i = 0; i < n; ++i) make_set(i);     g.resize(n);     bool ok1 = 1, ok2 = 1, ok3 = 1;     bool ok4 = 1;     if (m > n) ok1 = 0;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       a--, b--;       g[a].push_back(b);       g[b].push_back(a);       if (g[a].size() > 2 || g[b].size() > 2) {         ok2 = 0;       }     }     dfs(0);     for (int i = 0; i < n; ++i) {       if (!used[i]) ok3 = 0;       if (g[i].size() != 2) ok4 = 0;     }     if (ok4 && ok3) {       cout <<  YES  << endl << 0;       return 0;     }     memset(used, 0, sizeof(used));     for (int i = 0; i < n; ++i) {       if (!used[i]) dfs(i);     }     if (!(ok1 && ok2 && ok)) {       cout <<  NO ;       return 0;     }     vector<pair<int, int>> ans;     vector<int> cur;     vector<int> deg(n);     for (int i = 0; i < n; ++i) {       deg[i] = g[i].size();       if (deg[i] <= 1) cur.push_back(i);     }     for (int i = 0; i < n; ++i) {       if (!used[i]) {         dfs(i);         cmp++;       }     }     vector<int> nd;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (deg[i] >= 2 || deg[j] >= 2) continue;         if (find_set(i) != find_set(j)) {           ans.push_back({i, j});           deg[i]++;           deg[j]++;           union_sets(i, j);         }       }     }     for (int i = 0; i < n; ++i) {       if (deg[i] <= 1) nd.push_back(i);     }     ans.push_back({nd[0], nd[nd.size() - 1]});     cout <<  YES n  << ans.size() <<   n ;     for (auto u : ans) cout << u.first + 1 <<     << u.second + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double m, n;     long long int r, a, b, c, d, dist, sim;     cin >> r >> a >> b >> c >> d;     dist = (c - a) * (c - a) + (d - b) * (d - b);     m = sqrt(dist);     m = m / 2;     c = m / r;     m = m / r;     if (m == c)       cout << c;     else       cout << c + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, bool> in;   int main() {     int n, mx = 0, arr[200], ans = 0;     char a[200];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> arr[i];       if (a[i] ==  + ) {         in[arr[i]] = true;         mx++;       } else if (a[i] ==  - ) {         if (in[arr[i]]) {           mx--;           in[arr[i]] = false;         } else           ans++;       }       ans = max(mx, ans);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << n / 2 << endl;     if (n % 2) {       while (n > 3) {         cout << 2 <<    ;         n -= 2;       }       cout << 3;     } else {       while (n) {         cout << 2 <<    ;         n -= 2;       }     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   long sail(char ar[], long a, long m, long n) {     for (int k = 0; k < a; k++) {       if (m > 0) {         if (ar[k] ==  E ) m--;       }       if (m < 0) {         if (ar[k] ==  W ) m++;       }       if (n > 0) {         if (ar[k] ==  N ) n--;       }       if (n < 0) {         if (ar[k] ==  S ) n++;       }       if (n == 0 && m == 0) {         return k + 1;       }     }     return -1;   }   int main() {     long a, b, c, d, e;     cin >> a >> b >> c >> d >> e;     char ar[100000];     for (int i = 0; i < a; i++) cin >> ar[i];     long m = d - b;     long n = e - c;     cout << sail(ar, a, m, n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, cnt = 0;     cin >> n;     for (long long i = 2; i <= sqrt(n); i++) {       long long int temp[n];       if ((i * i * i) <= n) cnt++;     }     cout << cnt + 1 << endl;   }   void opti() {     long long int n;     cin >> n;     set<int> a;     for (int i = 1; i * i <= n; i++) {       a.insert(i * i);     }     for (int i = 1; i * i * i <= n; i++) {       a.insert(i * i * i);     }     cout << a.size() << endl;   }   int main() {     int t;     cin >> t;     while (t--) opti();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, p[2000], d[2000], s[2000];     cin >> n >> m;     for (int i = 0; i < 2 * n; ++i) cin >> p[i];     array<int, 2> a[1000];     memset(d, -1, sizeof(d));     for (int i = 0; i < m; ++i) {       cin >> a[i][0] >> a[i][1], --a[i][0], --a[i][1];       if (p[a[i][0]] < p[a[i][1]]) swap(a[i][0], a[i][1]);       d[a[i][0]] = a[i][1];       d[a[i][1]] = a[i][0];     }     int t, ns = -1, x;     cin >> t, --t;     for (int it = 0; it < 2 * n; ++it) {       if (t) {         cin >> x, --x;         if (d[x] != -1 && !s[d[x]])           ns = d[x];         else           ns = -1;         s[x] = 1;       } else {         if (ns != -1) {           cout << ns + 1 << endl;           s[ns] = 1;         } else {           bool b = 0;           for (int i = 0; i < m && !b; ++i) {             if (!s[a[i][0]]) {               cout << a[i][0] + 1 << endl;               s[a[i][0]] = 1;               b = 1;             }           }           if (!b) {             int m1 = -1;             for (int i = 0; i < 2 * n; ++i)               if (!s[i] && (m1 == -1 || p[m1] < p[i])) m1 = i;             cout << m1 + 1 << endl;             s[m1] = 1;           }         }       }       t ^= 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int l, r;     int p = 0, j = 0, i = 0, len = 0, cnt = 0;     while (j < n) {       if (a[j] == 0) {         cnt++;       }       while (cnt > k) {         if (a[i] == 0) cnt--;         i++;       }       if (j - i + 1 > len) {         l = i;         r = j;         len = j - i + 1;       }       j++;     }     cout << len << endl;     for (i = 0; i < n; i++) {       if (i >= l && i <= r)         cout << 1 <<    ;       else         cout << a[i] <<    ;     }   }