malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int tobin(string s) {     int ans = 0;     for (int i = 0; i < s.size(); i++) {       ans |= 1 << (s[i] -  a );     }     return ans;   }   int main() {     int n, mask, save = 0;     cin >> n;     mask = (1 << 26) - 1;     while (n--) {       char c, c2;       string s;       cin >> c;       if (c ==  . ) {         cin >> s;         mask &= ~tobin(s);       }       if (c ==  ! ) {         if (__builtin_popcount(mask) == 1) save++;         cin >> s;         mask &= tobin(s);       }       if (c ==  ? ) {         if (__builtin_popcount(mask) == 1 && n != 0) save++;         cin >> c2;         mask &= ~(1 << (int)(c2 -  a ));       }     }     cout << save <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long max_n = 1000006;   inline long long read() {     long long x = 0;     bool w = 0;     char c = getchar();     while (c <  0  || c >  9 ) w |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return w ? -x : x;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 ^ 48);   }   long long n, a[max_n], t[max_n], pr[max_n];   struct unionfind {     long long fa[max_n], sz[max_n];     inline void clear() {       for (register long long i = 0; i <= n; ++i) fa[i] = i;     }     inline long long find(long long x) {       if (fa[x] == x) return x;       return fa[x] = find(fa[x]);     }     inline void merge(long long x, long long y) {       x = find(x), y = find(y);       if (x == y) return;       fa[x] = y;     }   } uf;   long long c[max_n], d[max_n];   inline void getpr() {     for (register long long i = 2; i < max_n; ++i)       if (!pr[i])         for (register long long j = i, k = 0; j < max_n; j += i) {           if (t[j]) {             if (!k)               c[i] = uf.find(t[j]);             else               uf.merge(k, t[j]);             k = t[j];           }           pr[j] = i;         }   }   map<pair<long long, long long>, bool> mp;   signed main() {     n = read();     long long T = read();     uf.clear();     for (register long long i = 1; i <= n; ++i) {       a[i] = read();       t[a[i]] = i;     }     getpr();     for (register long long i = 2; i < max_n; ++i)       if (pr[i] == i) c[i] = uf.find(c[i]);     for (register long long i = 1; i <= n; ++i) {       long long j = a[i] + 1, cnt = 0;       d[++cnt] = uf.find(i);       while (j != 1) {         d[++cnt] = c[pr[j]];         j /= pr[j];       }       sort(d + 1, d + 1 + cnt), cnt = unique(d + 1, d + 1 + cnt) - d - 1;       for (register long long j = 1; j < cnt; ++j)         for (register long long k = j + 1; k <= cnt; ++k)           mp[make_pair(d[j], d[k])] = 1;     }     while (T--) {       long long x = read(), y = read();       x = uf.find(x), y = uf.find(y);       if (x == y) {         puts( 0 );         continue;       }       if (x > y) x ^= y ^= x ^= y;       if (mp[make_pair(x, y)])         puts( 1 );       else         puts( 2 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     bool g;     int n, m[5001] = {0}, x;     cin >> n;     if (n % 2 == 1) {       v.push_back(1);       m[1] = 1;     } else {       v.push_back(2);       m[2] = 1;     }     while (true) {       g = false;       for (int i = 1; i <= n; i++) {         if (!m[i] && abs(v.back() - i) != 1) {           v.push_back(i);           m[i] = 1;           g = true;         }       }       if (!g) break;     }     cout << v.size() <<   n ;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp_pos[1000010], dp_neg[1000010];   int mark_pos[1000010], mark_neg[1000010];   int pos[1000010], neg[1000010], cnt_pos = 0, cnt_neg = 0;   int max_pos, max_neg;   int a[1000010];   void calc(int* dp, int* mark) {     int cnt = 0, i, j;     for (i = 0; i <= max_pos * max_neg; i++) dp[i] = 10000000;     for (i = 0; i <= 1000; i++)       if (mark[i]) a[cnt++] = i;     for (i = 0; i < cnt; i++) dp[a[i]] = 1;     for (i = 1; i <= max_pos * max_neg; i++)       for (j = 0; j < cnt && a[j] <= i; j++) dp[i] = min(dp[i], 1 + dp[i - a[j]]);   }   int main() {     int n, k, i;     scanf( %d , &n);     scanf( %d , &k);     memset(mark_pos, 0, sizeof(mark_pos));     memset(mark_neg, 0, sizeof(mark_neg));     for (i = 0; i < k; i++) {       int x;       scanf( %d , &x);       if (x >= n)         mark_pos[x - n] = 1;       else         mark_neg[n - x] = 1;     }     if (mark_pos[0]) {       printf( 1 n );       return 0;     }     max_pos = max_neg = -10000000;     for (i = 0; i <= 1000; i++)       if (mark_pos[i]) max_pos = i;     for (i = 0; i <= 1000; i++)       if (mark_neg[i]) max_neg = i;     if (max_neg == -10000000 || max_pos == -10000000) {       printf( -1 n );       return 0;     }     calc(dp_pos, mark_pos);     calc(dp_neg, mark_neg);     int ans = 2 * 10000000;     for (i = 1; i <= max_neg * max_pos; i++)       ans = min(ans, dp_pos[i] + dp_neg[i]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, check = 0;     string x;     cin >> n >> x;     sort(x.begin(), x.end());     if (n == 1)       cout <<  YES ;     else {       for (int i = 0; i < x.size() - 1; i++) {         if (x[i] == x[i + 1]) {           check = 1;           break;         }       }       if (check == 1)         cout <<  YES ;       else         cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 10;   using namespace std;   map<int, int> mp;   struct a {     int x, y, z;   };   vector<a> res;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       int t;       cin >> t;       mp[t]++;     }     priority_queue<pair<int, int>> pq;     for (auto it = mp.begin(); it != mp.end(); ++it) {       int fi = it->second;       int se = it->first;       pq.push({fi, se});     }     while (pq.size() >= 3) {       auto xx = pq.top();       pq.pop();       auto yy = pq.top();       pq.pop();       auto zz = pq.top();       pq.pop();       a temp;       temp.x = xx.second;       temp.y = yy.second;       temp.z = zz.second;       res.push_back(temp);       if (xx.first - 1) {         pq.push({xx.first - 1, xx.second});       }       if (yy.first - 1) {         pq.push({yy.first - 1, yy.second});       }       if (zz.first - 1) {         pq.push({zz.first - 1, zz.second});       }     }     cout << res.size() <<   n ;     for (int i = 0; i < res.size(); ++i) {       int b[3];       b[0] = res[i].x;       b[1] = res[i].y;       b[2] = res[i].z;       sort(b, b + 3);       cout << b[2] <<     << b[1] <<     << b[0] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[10000], b[10000];   long long res[10000];   int val[10000];   map<long long, int> mp;   int main() {     int n;     long long ans = 0;     int len = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       mp[a[i]]++;       if (mp[a[i]] == 2) res[++len] = a[i];     }     for (int i = 1; i <= n; i++) {       cin >> b[i];     }     for (int i = 1; i <= len; i++) {       for (int j = 1; j <= n; j++) {         if ((res[i] & a[j]) == a[j]) val[j] = 1;       }     }     for (int i = 1; i <= n; i++) {       ans += val[i] * b[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void deba(T *a, int n) {     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   const int N = 5e5 + 10, M = 5e5 + 10;   long long n, m, c[N], t[N], num, ans[N];   vector<pair<long long, long long> > e3[N];   vector<long long> e2[M];   bool mark[M];   vector<long long> e[M], er[M], topSort;   long long topSort_num[M], comp[M], cnt_comp;   void add(long long x, long long y) {     e2[x ^ 1].push_back(y);     e2[y ^ 1].push_back(x);   }   void topol(long long x) {     mark[x] = 1;     for (auto u : e[x])       if (!mark[u]) topol(u);     topSort.push_back(x);     topSort_num[x] = topSort.size();   }   void dfs(long long x) {     comp[x] = cnt_comp;     for (auto u : er[x])       if (!comp[u]) dfs(u);   }   bool check(long long x, bool exx = 0) {     topSort.clear();     memset(mark, 0, sizeof(mark));     memset(comp, 0, sizeof(comp));     cnt_comp = 1;     for (int i = 0; i < 2 * num; i++) e[i] = e2[i];     for (int i = 0; i < m; i++)       if (t[i] > x) e[2 * i + 1].push_back(2 * i);     for (int i = 0; i < 2 * num; i++)       if (!mark[i]) topol(i);     reverse(topSort.begin(), topSort.end());     for (int i = 0; i < 2 * num; i++) er[i].clear();     for (int i = 0; i < 2 * num; i++)       for (auto u : e[i]) er[u].push_back(i);     for (auto u : topSort)       if (!comp[u]) {         dfs(u);         cnt_comp++;       }     for (int i = 0; i < m; i++) {       if (comp[2 * i] == comp[2 * i + 1]) return 0;       if (comp[2 * i + 1] > comp[2 * i])         ans[i] = 1;       else         ans[i] = 0;     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     num = m;     for (int i = 0; i < m; i++) {       long long v, u;       cin >> v >> u >> c[i] >> t[i];       e3[v].push_back({c[i], i});       e3[u].push_back({c[i], i});     }     for (int i = 1; i < n + 1; i++) {       if (!e3[i].size()) continue;       bool flg = 0;       long long id;       sort(e3[i].begin(), e3[i].end());       for (int j = 1; j < e3[i].size(); j++) {         if (e3[i][j].first == e3[i][j - 1].first && flg) {           cout <<  No ;           return 0;         }         if (e3[i][j].first == e3[i][j - 1].first) flg = 1, id = j;       }       if (flg) add(2 * e3[i][id].second + 1, 2 * e3[i][id - 1].second + 1);       long long lst = e3[i][0].second;       for (int j = 1; j < e3[i].size(); j++) {         long long ex = e3[i][j].second;         add(2 * lst, 2 * ex);         add(2 * ex, 2 * num + 1);         add(2 * lst, 2 * num + 1);         lst = num++;       }     }     long long l = -1, r = (long long)N * 10000;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     if (r == N * 10000) {       cout <<  No ;       return 0;     }     check(r, 1);     long long res = 0;     for (int i = 0; i < m; i++) res += ans[i];     cout <<  Yes n  << r <<     << res <<   n ;     for (int i = 0; i < m; i++)       if (ans[i]) cout << i + 1 <<    ;     cin >> n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m1, m2;   long long C[4005][4005], f[4005], ret;   long long MOD = 1000000009;   int main() {     for (int i = 0; i <= 4000; i++) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;     }     f[0] = 1;     for (int i = (1); i <= (4000); i++) f[i] = (f[i - 1] * i) % MOD;     ret = 0;     scanf( %d%d%d , &n, &m1, &m2);     for (int i = (1); i <= (m1); i++)       for (int j = (1); j <= (m2); j++)         if (i + j < n && n - j <= m1) {           ret += C[m2 - 1][j - 1] * f[m2] % MOD * C[m1 - 1][n - j - 1] % MOD *                  f[m1] % MOD;           ret %= MOD;         }     printf( %d n , (int)ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int maxm = 305;   long long a[maxn];   long long c[11][maxn];   long long num[maxn];   long long n, m, v, k;   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long ans = 0;     ans += (a[n - 1] * k + a[n - 2]) * (m / (k + 1));     long long mod = m % (k + 1);     ans += (a[n - 1]) * mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, i, j, k, l, T, u, v, q, t = 0, t1 = 0, te, c = 0;   long long int a[1010], b[1010];   long long int gcd(long long int p, long long int q) {     if (q == 0)       return p;     else       return gcd(q, p % q);   }   int main() {     std::ios::sync_with_stdio(false);     long long int t, w, b;     cin >> t >> w >> b;     long long int g = gcd(max(w, b), min(w, b)), lcm, ans = 0;     double l = w;     l = l * b;     l = l / g;     if (l <= 6e18) {       lcm = w / g;       lcm = lcm * b;       w = min(w, b);       ans = t / lcm;       ans = ans * w;       ans += min(t % lcm, w - 1);     } else {       w = min(w, b);       lcm = t + 1;       ans += min(t % lcm, w - 1);     }     g = gcd(t, ans);     t = t / g;     ans = ans / g;     cout << ans <<  /  << t;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long head[1100000], a[1100000];   struct node {     long long v, nex;   } bian[2100000];   long long cnt;   void add(long long x, long long y) {     bian[++cnt].v = y;     bian[cnt].nex = head[x];     head[x] = cnt;   }   long long tot[1100000], d[1100000], f[1100000], zong;   void dfs(long long x, long long fa) {     tot[x] = 1;     for (long long i = head[x]; i; i = bian[i].nex) {       long long v = bian[i].v;       if (v == fa) continue;       dfs(v, x);       tot[x] += tot[v];     }     f[1] += tot[x];   }   long long ans = 0;   void dp(long long x, long long fa) {     ans = max(ans, f[x]);     for (long long i = head[x]; i; i = bian[i].nex) {       long long v = bian[i].v;       if (v == fa) continue;       f[v] = f[x] - tot[v] + n - tot[v];       dp(v, x);     }   }   signed main() {     cin >> n;     for (long long i = 1; i < n; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       add(x, y), add(y, x);     }     dfs(1, 0);     dp(1, 0);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long N, K, L, R;   long long G, A;   long long ans;   void run(int use, long long ntot) {     if (N <= 500000) {       for (int nplus = 0; nplus <= N - 1; nplus++) {         long long rr = (N + nplus + use);         long long rv = G + (1 + use);         long long nbefore = ((ntot - rv) % rr + rr) % rr;         long long nafter = nplus - nbefore;         if (nbefore >= 0 && nbefore <= G && nafter >= 0 && nafter <= A)           ans = max(ans, (long long)nplus + use);       }     } else {       if (G + 1 + use <= ntot) {         long long rv = ntot - G - 1 - use;         if (rv <= G) ans = max(ans, rv + use + A);       }       for (int nrun = 1; nrun * N <= ntot; nrun++) {         long long nstart = (nrun * (N + use)) + (G + 1 + use);         long long nleft = ntot - nstart;         if (nleft >= 0) {           long long nbefore = nleft % nrun;           long long nafter = (nleft - ((nrun + 1) * (nbefore))) / nrun;           if (nafter > A) {             long long ndrop = (nafter - A + nrun) / (nrun + 1);             nafter -= ndrop * (nrun + 1);             nbefore += ndrop * nrun;           }           if (nafter >= 0 && nafter <= A && nbefore >= 0 && nbefore <= G)             ans = max(ans, nbefore + nafter + use);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> N >> L >> R >> K;     G = (R - L + N) % N;     A = (N - 1 - G);     ans = -1;     for (int i = 0; i <= 1; i++) {       for (int j = 0; j <= i; j++) {         run(i, K + j);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   const int MAXN = 312345;   int n, m;   vector<long long> s[4];   struct pd {     long long x;     int i[3];     pd(long long xx, int ii, int iii) {       x = xx;       i[1] = ii;       i[2] = iii;     }     pd() {}     bool operator<(const struct pd &o) const {       return (x < o.x || (x == o.x && i[1] < o.i[1]));     }   } dp[MAXN];   bool cmp(int a, int b) { return a > b; }   int main() {     scanf( %d %d , &n, &m);     long long res = 0;     for (int a = 0; a < n; a++) {       long long w, val;       scanf( %lld %lld , &w, &val);       s[w].push_back(val);       if (w == 3) res += val;     }     for (int i = 1; i <= 3; i++) sort(s[i].begin(), s[i].end(), cmp);     dp[0] = (pd){0, 0, 0};     for (int i = 0; i < m; i++) {       dp[i + 1] = max(dp[i], dp[i + 1]);       if (dp[i].i[1] != s[1].size())         dp[i + 1] = max(dp[i + 1], pd(dp[i].x + s[1][dp[i].i[1]], dp[i].i[1] + 1,                                       dp[i].i[2]));       if (dp[i].i[2] != s[2].size())         dp[i + 2] = max(dp[i + 2], pd(dp[i].x + s[2][dp[i].i[2]], dp[i].i[1],                                       dp[i].i[2] + 1));       ;     }     int i = 0, j = 0;     long long ans = 0;     for (int k = s[3].size(); k >= 0; k--) {       if (m < 3 * k) {         if (k > 0) {           res -= s[3][k - 1];         }         continue;       }       int sob = m - 3 * k;       ans = max(ans, res + dp[sob].x);       if (k > 0) res -= s[3][k - 1];     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005, MOD = 1e9 + 7;   int d, n, a[N], dp[N], rt;   vector<int> g[N];   void dfs(int v, int pr = -1) {     dp[v] = 1;     for (int to : g[v]) {       if (to == pr) {         continue;       }       if (a[to] < a[rt] || a[to] > a[rt] + d) {         continue;       }       if (a[to] == a[rt] && to > rt) {         continue;       }       dfs(to, v);       dp[v] = (1ll * dp[v] * (dp[to] + 1)) % MOD;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> d >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       rt = i;       dfs(rt, -1);       ans = (ans + dp[i]) % MOD;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, d, i, j;     cin >> k >> d;     if (d != 0) {       for (i = 1; i <= k; i++) {         if (i == 1)           cout << d;         else           cout << 0;       }     }     if (d == 0) {       if (k == 1)         cout << 0;       else         cout <<  No solution ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long tot, n, w, b, x;   deque<pair<long long, long long> > maxq;   void add(long long val, long long pos) {     while (maxq.size() > 0 && maxq.back().first <= val) maxq.pop_back();     maxq.push_back({val, pos});   }   long long query() { return maxq.front().first; }   void erase(long long pos) {     while (maxq.size() > 0 && maxq.front().second < pos) maxq.pop_front();   }   int main() {     cin >> n >> w >> b >> x;     long long c[n], cost[n];     for (int i = 0; i < n; i++) cin >> c[i];     for (int j = 0; j < n; j++) cin >> cost[j];     long long dp[n][10005], temp;     for (int i = 0; i < n; i++)       for (int j = 0; j < 10005; j++) dp[i][j] = -1000000000000ll * n;     for (long long j = 0; j < 10001; j++) {       if (j <= c[0]) {         if (w - cost[0] * j < 0)           dp[0][j] = -1000000000000ll * n;         else           dp[0][j] = min(w + b * j, w - cost[0] * j + x);       } else         dp[0][j] = -1000000000000ll * n;     }     for (int i = 1; i < n; i++) {       maxq.clear();       tot = 0;       for (long long j = 0; j < 10001; j++) {         add(dp[i - 1][j] - tot, j);         temp = query() + tot;         if (temp < 0)           dp[i][j] = -1000000000000ll * n;         else           dp[i][j] = min(w + b * j, temp + x);         tot -= cost[i];         erase(j - c[i] + 1);       }     }     for (int i = 10000; i >= 0; i--) {       if (dp[n - 1][i] >= 0) {         cout << i << endl;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     long long int n = s.size();     map<char, long long int> r;     for (long long int i = 0; i < n; i++) {       r[s[i]]++;     }     long long int k = 0, cnt = 0;     for (auto it = r.begin(); it != r.end(); it++) {       if (it->second >= 2)         k++;       else if (it->second == 1)         cnt++;     }     cout << k + cnt / 2 <<   n ;     return;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int t = 1;     cin >> t;     for (long long int i = 1; i < t + 1; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isVowel(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u );   }   int main() {     vector<string> v;     int cnt[] = {5, 7, 5};     for (int i = 0; i < 3; i++) {       string s;       char c;       cin >> c;       getline(cin, s);       s = c + s;       v.push_back(s);     }     for (int i = 0; i < 3; i++) {       int c = 0;       for (auto u : v[i]) {         if (isVowel(u)) c++;       }       if (c != cnt[i]) return cout <<  NO n , 0;     }     cout <<  YES n ;   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( Sisend.txt );   long long t, n, m, arv;   string s[105];   vector<int> v;   void pane(int i1, int j1, int i2, int j2, int i3, int j3) {     v.emplace_back(i1 + 1), v.emplace_back(j1 + 1), v.emplace_back(i2 + 1),         v.emplace_back(j2 + 1), v.emplace_back(i3 + 1), v.emplace_back(j3 + 1);     if (s[i1][j1] ==  0 )       s[i1][j1] =  1 ;     else       s[i1][j1] =  0 ;     if (s[i2][j2] ==  0 )       s[i2][j2] =  1 ;     else       s[i2][j2] =  0 ;     if (s[i3][j3] ==  0 )       s[i3][j3] =  1 ;     else       s[i3][j3] =  0 ;     arv++;   }   vector<int> x = {1, 0, -1, 0, 1, 0, -1, 0}, y = {0, 1, 0, -1, 0, 1, 0, -1};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     cin >> t;     while (t--) {       v.resize(0);       arv = 0;       cin >> n >> m;       for (int(i) = (0); ((i)) < ((n)); ((i))++) cin >> s[i];       for (int(i) = (0); ((i)) < ((n - 2)); ((i))++)         for (int(j) = (0); ((j)) < ((m)); ((j))++)           if (j % 2 or j == m - 1)             if (s[i][j] ==  1  and s[i][j - 1] ==  1 )               pane(i, j - 1, i, j, i + 1, j);             else if (s[i][j] ==  1 )               pane(i, j, i + 1, j - 1, i + 1, j);             else if (s[i][j - 1] ==  1 )               pane(i, j - 1, i + 1, j - 1, i + 1, j);       int i = n - 2;       for (int(j) = (0); ((j)) < ((m - 1)); ((j))++)         if (s[i][j] ==  1  and s[i + 1][j] ==  1 )           pane(i, j, i, j + 1, i + 1, j);         else if (s[i][j] ==  1 )           pane(i, j, i, j + 1, i + 1, j + 1);         else if (s[i + 1][j] ==  1 )           pane(i + 1, j, i, j + 1, i + 1, j + 1);       int j = m - 1;       if (s[i][j] ==  1  and s[i + 1][j] ==  1 ) {         pane(i, j, i, j - 1, i + 1, j - 1);         pane(i + 1, j, i, j - 1, i + 1, j - 1);       } else if (s[i][j] ==  1 ) {         pane(i, j, i, j - 1, i + 1, j - 1);         pane(i, j, i, j - 1, i + 1, j);         pane(i + 1, j - 1, i, j, i + 1, j);       } else if (s[i + 1][j] ==  1 ) {         pane(i + 1, j, i, j - 1, i + 1, j - 1);         pane(i, j, i, j - 1, i + 1, j);         pane(i + 1, j - 1, i, j, i + 1, j);       }       cout << arv << endl;       for (int(i) = (0); ((i)) < ((v.size())); ((i))++) {         cout << v[i] <<    ;         if ((i + 1) % 6 == 0) cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   int n, k, p[N], gk[256], gl[256];   int main() {     cin >> n >> k;     memset(gk, -1, sizeof(gk));     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) {       int cc = p[i];       if (gk[cc] == -1) {         int leftmost, len = 0;         for (int j = cc; j >= 0 && gk[j] == -1 && len < k; j--) {           leftmost = j;           len++;         }         if (leftmost > 0 && len < k && gl[leftmost - 1] + len <= k) {           len += gl[leftmost - 1];           leftmost = gk[leftmost - 1];         }         for (int j = cc; j >= leftmost; j--) {           gk[j] = leftmost;           gl[j] = len;         }       }       p[i] = gk[cc];     }     for (int i = 0; i < n; i++) {       cout << p[i] <<    ;     }     cout <<   n ;     return 0;   }