malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t, n;     cin >> t;     while (t--) {       string A, B;       cin >> n;       cin >> A >> B;       int f = 1;       for (int i = 0; i < n; ++i) {         if (A[i] > B[i]) f = 0;       }       if (!f) {         cout << -1 <<   n ;         continue;       }       int ans = 0;       for (int i = 0; i < 26; ++i) {         bitset<27> good;         for (int j = 0; j < n; ++j) {           if (A[j] == B[j]) continue;           if (B[j] == char( a  + i)) {             good[A[j] -  a ] = 1;           }         }         ans += good.count();         for (int j = 0; j < n; ++j) {           if (A[j] == B[j]) continue;           if (good[A[j] -  a ] == 1) A[j] = char( a  + i);         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   int n, k;   vector<pair<int, int> > g[M];   int ans;   int dp[M][2];   void dfs(int u, int Pa) {     vector<pair<int, int> > ch;     for (auto p : g[u]) {       int v = p.first, w = p.second;       if (v == Pa) continue;       dfs(v, u);       ch.push_back(make_pair(dp[v][0] + w, dp[v][1] + w));     }     bool flag = ch.size() > 0;     if (flag) {       sort(ch.begin(), ch.end(), [&](pair<int, int> a, pair<int, int> b) {         return a.second > b.second;       });     }     for (int i = 0; i < k - 1 && i < ch.size(); i++) {       dp[u][1] += ch[i].second;     }     if (ch.size() <= k) {       for (auto p : ch) {         dp[u][0] += p.second;       }       if (flag) {         sort(ch.begin(), ch.end(), [&](pair<int, int> a, pair<int, int> b) {           return a.first - a.second > b.first - b.second;         });         dp[u][0] += ch[0].first - ch[0].second;       }     } else {       int max_val = -1e9;       for (int i = k; i < ch.size(); i++) {         max_val = max(max_val, ch[i].first);       }       int sum = 0;       for (int i = 0; i < k; i++) {         sum += ch[i].second;       }       for (int i = 0; i < k; i++) {         dp[u][0] = max(dp[u][0], sum - ch[i].second + max(max_val, ch[i].first));       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; i++) {       int u, v, c;       scanf( %d%d%d , &u, &v, &c);       u++, v++;       g[u].push_back(make_pair(v, c));       g[v].push_back(make_pair(u, c));     }     dfs(1, 0);     printf( %d n , dp[1][0]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   int arr[N], n, inc[N], decr[N];   int tree[4 * N];   int update(int pos, int l, int r, int x, int v) {     if (l > x || r < x) return tree[pos];     if (l == r) return tree[pos] = max(tree[pos], v);     int mid = (l + r) / 2;     return tree[pos] = max(update(pos * 2, l, mid, x, v),                            update(pos * 2 + 1, mid + 1, r, x, v));   }   int get(int pos, int l, int r, int qLow, int qHigh) {     if (l > qHigh || r < qLow) return 0;     if (l >= qLow && r <= qHigh) return tree[pos];     int mid = (l + r) / 2;     return max(get(pos * 2, l, mid, qLow, qHigh),                get(pos * 2 + 1, mid + 1, r, qLow, qHigh));   }   int bitonic() {     int i, max;     inc[1] = 1;     update(1, 0, n, arr[1], 1);     for (i = 2; i <= n; i++) {       int x = get(1, 0, n, 0, arr[i]);       inc[i] = x + 1;       update(1, 0, n, arr[i], inc[i]);     }     memset(tree, 0, sizeof tree);     decr[n] = 1;     update(1, 0, n, arr[n], 1);     for (i = n - 1; i > 0; i--) {       int x = get(1, 0, n, 0, arr[i]);       decr[i] = x + 1;       update(1, 0, n, arr[i], decr[i]);     }     max = 0;     for (i = 0; i <= n; i++)       if (inc[i] + decr[i] - 1 > max) max = inc[i] + decr[i] - 1;     return max;   }   int main() {     int a, b;     scanf( %d%d , &a, &n);     for (int i = 0; i < a; i++) {       int x, y;       scanf( %d%d , &x, &y);       arr[x]++, arr[y + 1]--;     }     for (int i = 1; i <= n; i++) arr[i] += arr[i - 1];     printf( %d , bitonic());     return 0;   }
#include <bits/stdc++.h>   int main() {     char s[50];     scanf( %s , s);     int i, l = strlen(s), flag = 0;     for (i = 0; i < l; i++) {       if (s[i] != s[l - i - 1]) flag++;     }     if (flag == 2)       printf( YES );     else if (flag == 0 && strlen(s) % 2 == 1)       printf( YES );     else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l, r, f[100];   bool check(string s, int x, int y) {     if (s.size() % x != 0) return false;     for (int i = 0; i + x < s.size() and i + x < y + 1; i++)       if (s[i] != s[i + x]) return false;     return true;   }   long long p(int x) {     long long ans = 0;     for (int i = 1; i <= x; i++)       if (x % i == 0) {         f[i] = pow(2, i - 1);       }     for (int j = 1; j < x; j++) {       if (x % j != 0) continue;       ans += f[j];       for (int u = j * 2; u < x; u += j) f[u] -= f[j];     }     return ans;   }   long long solve(long long a) {     long long ans = 0;     string s =   ;     while (a) {       s += (a % (long long)2) +  0 ;       a /= (long long)2;     }     reverse(s.begin(), s.end());     bool no = 0;     for (int i = 1; i < s.size(); i++) {       if (check(s, i, 100000)) {         no = 1;       }     }     for (int i = 1; i < s.size(); i++) {       if (s[i] ==  0 ) continue;       s[i] =  0 ;       for (int j = 1; j <= i; j++) {         f[j] = check(s, j, i);       }       for (int j = i + 1; j < s.size(); j++) f[j] = pow(2, j - i - 1);       s[i] =  1 ;       for (int j = 1; j < s.size(); j++) {         if (s.size() % j != 0) continue;         ans += f[j];         for (int u = j * 2; u < s.size(); u += j) f[u] -= f[j];       }     }     for (int i = s.size() - 1; i >= 1; i--) ans += p(i);     ans += no;     return ans;   }   int main() {     scanf( %lld%lld , &l, &r);     printf( %lld , solve(r) - solve(l - 1));   }
#include <bits/stdc++.h>   long long z;   int l, r, i, j, k, ans;   short p;   std::vector<short> prm;   std::vector<int> to;   short dp[3000111];   bool done[3000111];   void dfs(long long now, char cnt) {     to.push_back(now);     for (; cnt < prm.size() && now * prm[cnt] <= r; ++cnt)       dfs(now * prm[cnt], cnt);   }   int main() {     prm.reserve(29);     to.reserve(3000111);     scanf( %d %d %hd , &l, &r, &p);     for (i = 2; i < p; ++i) {       for (j = 2; j * j <= i; ++j)         if (i % j == 0) break;       if (j * j > i) prm.push_back(i);     }     dfs(1, 0);     std::sort(to.begin(), to.end());     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (i = 2; i < p; ++i)       for (j = 0, k = 1; j < to.size(); ++j) {         for (z = to[j] * i; k < to.size() && to[k] < z; ++k)           ;         if (to[k] == z && dp[k] > dp[j] + 1) {           dp[k] = dp[j] + 1;           if (i + dp[k] <= p) done[k] = true;         }       }     r = std::min(r, to.back());     for (i = 0; i < to.size() && to[i] < l; ++i)       ;     for (; i < to.size() && to[i] <= r; ++i)       if (done[i]) ++ans;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long N;   long long fac(long long x) {     long long res = 1;     for (int i = 1; i <= x; ++i) res = res * i % mod;     return res;   }   long long qpow(long long x, long long y) {     long long res = 1;     for (; y; x = x * x % mod, y >>= 1)       if (y & 1) res = res * x % mod;     return res;   }   int main() {     scanf( %lld , &N);     long long fz = fac(2 * N - 1), fm = fac(N - 1) * fac(N) % mod;     printf( %lld n , (2 * fz % mod * qpow(fm, mod - 2) % mod - N + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long int> > dp;   vector<long long int> a;   long long int check(long long int l, long long int r) {     if (l >= r) return 0;     if (dp[l][r]) return dp[l][r];     if (l + 1 == r) {       dp[l][r] = a[r];       return a[r];     }     dp[l][r] = -1;     for (int m = l + 1; m < r; ++m) {       long long int lf = check(l, m), rt = check(m, r);       if (lf > 0 && lf == rt) {         dp[l][r] = lf + 1;         return lf + 1;       }     }     return dp[l][r];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     a.resize(n + 1);     for (int i = 1; i <= n; ++i) cin >> a[i];     dp.assign(n + 1, vector<long long int>(n + 1, 0));     vector<long long int> ans(n + 1, 1e9);     ans[0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (check(i, j) > 0) ans[j] = min(ans[j], ans[i] + 1);       }     }     cout << ans[n];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, B, c;     cin >> n >> k >> B >> c;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long x = *min_element(a, a + n);     for (int i = 0; i < n; i++) a[i] = a[i] - x;     B = min(B, 5 * c);     long long ans = 1e18;     for (int t = 0; t < 5; t++) {       pair<long long, long long> b[n];       for (int i = 0; i < n; i++) {         b[i] = {a[i], 0};         while (b[i].first % 5 != t) {           b[i].first++;           b[i].second += c;         }         b[i].first /= 5;       }       sort(b, b + n);       priority_queue<long long> G;       long long suma = 0;       for (int i = 0; i < n; i++) {         if (G.size() >= k - 1) {           ans = min(ans, b[i].second + b[i].first * B * (k - 1) + suma);         }         G.push(b[i].second - b[i].first * B);         suma += b[i].second - b[i].first * B;         while (G.size() >= k) {           suma -= G.top();           G.pop();         }       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int N = -1;   int main() {     int X = in(), d = in();     vector<long long> v;     v.push_back(0);     int b = 0;     while (X) {       if (X % 2) {         v.push_back(v.back() + d);         long long back = v.back();         for (int j = 0; j < b; j++) v.push_back(back + d);       }       X /= 2;       b++;     }     cout << (int)v.size() - 1 << endl;     for (int i = 1; i < v.size(); i++) cout << v[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, branch[10001], total;   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       branch[a]++, branch[b]++;     }     for (int i = 1; i <= n; i++) total += branch[i] * (branch[i] - 1) / 2;     cout << total << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = -1;     cin >> n;     int a[n], l[n], r[n];     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0, des = 0; i < n; ++i) {       ++des;       l[i] = des = min(des, a[i]);     }     for (int i = n - 1, des = 0; i >= 0; --i) {       ++des;       r[i] = des = min(des, a[i]);     }     for (int i = 0; i < n; ++i) ans = max(ans, min(l[i], r[i]));     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b) {     return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL;   }   inline long long mul(long long a, long long b) {     return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL;   }   inline long long sub(long long a, long long b) {     return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) %            1000000007LL;   }   void prefixInversionAndSwap(string &ss, long long x) {     for (long long i = 0; i <= x; i++) {       if (ss[i] ==  0 ) {         ss[i] =  1 ;       } else {         ss[i] =  0 ;       }     }     for (long long i = 0; i <= (x / 2); i++) {       swap(ss[i], ss[x - i]);     }     return;   }   void Flash() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     vector<long long> ans;     long long swapped = 0;     long long ind = 0, nai, bbit;     long long firstBit = a[0] -  0 ;     for (long long i = (n - 1); i > 0; i--) {       if (swapped) {         nai = (a[ind - i] -  0 );         nai ^= 1;       } else {         nai = (a[ind + i] -  0 );       }       bbit = b[i] -  0 ;       if (nai != bbit) {         if (nai == 1) {           if (firstBit == 0) {             ans.push_back(1);           }           ans.push_back(i + 1);           if (swapped) {             ind -= i;           } else {             ind += i;           }           swapped ^= 1;           firstBit = (nai ^ 1);         } else {           if (firstBit == 1) {             ans.push_back(1);           }           ans.push_back(i + 1);           if (swapped) {             ind -= i;           } else {             ind += i;           }           swapped ^= 1;           firstBit = (nai ^ 1);         }       }     }     if (firstBit != (b[0] -  0 )) {       ans.push_back(1);     }     cout << ans.size() <<    ;     for (auto it : ans) {       cout << it <<    ;     }     cout <<   n ;   }   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     ;     long long t = 1;     cin >> t;     for (long long i = 1; i <= t; i++) {       Flash();     }     return 0;   }
#include <bits/stdc++.h>   #define int long long   using namespace std;      pair<int, int> extgcd(int a, int b) {       if(!b) return {1, 0};       pair<int, int> val = extgcd(b, a % b);       return {val.second, val.first - (a / b) * val.second};   }      signed main(){       ios_base::sync_with_stdio(false);       cin.tie(0);       int t; cin >> t;       while(t--){           int n; cin >> n;           string s; cin >> s;           int cnt = 0, cnt2 = 0;           for(int i = 0; i < n; ++i){               if(s[i] ==  1  && s[i + 1] ==  1 ){                   ++cnt; ++i;               }               else if(s[i] ==  1 ){                   ++cnt2;               }           }           int ans = 1, mod = 998244353, can = n - 1 - cnt2;           for(int i = n - cnt - cnt2; i > cnt; --i){               ans *= i; ans %= mod;           }           for(int i = n - cnt - cnt - cnt2; i >= 1; --i){               ans *= (extgcd(i, mod).first + mod) % mod; ans %= mod;           }           cout << ans <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int countbit(int n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); }   int lowbit(int n) { return (n ^ (n - 1)) & n; }   const double pi = acos(-1.0);   const double eps = 1e-11;   template <class T>   T sqr(T x) {     return x * x;   }   int n, m, k;   int c[101], clen;   bool Nim(int k) {     for (int i = 0; i < 8; ++i) {       int sum = 0;       for (int j = 0; j < clen; ++j) sum += (c[j] >> i) & 1;       if (sum % (k + 1)) return true;     }     return false;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int aw = 0, bw = 0;     for (int i = 0; i < n; ++i) {       char str[101];       char *pos, *pos1, *pos2;       scanf( %s , str);       pos = strchr(str,  - );       pos2 = strchr(str,  R );       pos1 = strchr(str,  G );       if (pos && !pos1 && pos2) bw = 1;       if (pos && !pos2 && pos1) aw = 1;       if (pos1 && pos2) c[clen++] = abs(pos1 - pos2) - 1;     }     if (aw && bw) {       printf( Draw n );       return 0;     } else if (aw) {       printf( First n );       return 0;     } else if (bw) {       printf( Second n );       return 0;     }     if (Nim(k))       printf( First n );     else       printf( Second n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class C>   inline void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   inline void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   const int INF = 1e9 + 7;   const int base = 1e9;   const int SIGMA = 26;   const int N = 1e5 + 7;   int n;   string s;   vector<int> ans;   void rec(int v) {     if (v == n) return;     if (s[v] ==  l ) {       ans.push_back(v);       rec(v + 1);     } else {       rec(v + 1);       ans.push_back(v);     }   }   int main() {     std::ios_base::sync_with_stdio(0);     cout << setprecision(15) << fixed;     cin >> s;     n = ((int)(s).size());     rec(0);     reverse((ans).begin(), (ans).end());     for (__typeof((ans).begin()) i = (ans).begin(); i != (ans).end(); ++i)       printf( %d n , *i + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool cmax(int &a, int b) { return (a < b) ? a = b, 1 : 0; }   bool cmin(int &a, int b) { return (a > b) ? a = b, 1 : 0; }   template <typename T>   T read() {     T ans = 0, f = 1;     char ch = getchar();     while (!isdigit(ch) && ch !=  - ) ch = getchar();     if (ch ==  - ) f = -1, ch = getchar();     while (isdigit(ch))       ans = (ans << 3) + (ans << 1) + (ch -  0 ), ch = getchar();     return ans * f;   }   void file() {}   int n, dep[N];   int same;   void input() {     n = read<int>();     for (register int i = (int)1; i <= (int)n + 1; ++i) {       dep[i] = read<int>();       if (dep[i] > 1 && dep[i - 1] > 1) same = i;     }   }   void work() {     int old = 0, now = 0;     if (!same) {       puts( perfect );       return;     }     puts( ambiguous );     for (register int i = (int)1; i <= (int)n + 1; ++i) {       for (register int j = (int)1; j <= (int)dep[i]; ++j) {         now++;         printf( %d  , old);       }       old = now;     }     printf(  n );     old = now = 0;     for (register int i = (int)1; i <= (int)n + 1; ++i) {       for (register int j = (int)1; j <= (int)dep[i]; ++j) {         now++;         if (i == same) {           printf( %d  , old - 1);           same = 0;         } else           printf( %d  , old);       }       old = now;     }   }   int main() {     file();     input();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100010];   long long dif[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= n - 1; i++) {       dif[i] = a[i + 1] - a[i];     }     long long d = 0;     for (int i = 1; i <= n - 1; i++)       if (dif[i] > 0) d += dif[i];     int q;     scanf( %d , &q);     printf( %lld n ,            ((a[1] + d) % 2) ? (((a[1] + d) >> 1) + 1) : (a[1] + d) >> 1);     for (int i = 0; i < q; i++) {       int l, r;       long long x;       scanf( %d%d%lld , &l, &r, &x);       if (l == 1) a[1] += x;       if (l != 1) {         dif[l - 1] += x;         if (dif[l - 1] > 0)           d += dif[l - 1] - (dif[l - 1] - x > 0 ? (dif[l - 1] - x) : (0));         else           d -= ((dif[l - 1] - x) > 0 ? (dif[l - 1] - x) : (0));       }       if (r != n) {         dif[r] -= x;         if (dif[r] > 0)           d += dif[r] - (dif[r] + x > 0 ? (dif[r] + x) : (0));         else           d -= (dif[r] + x > 0 ? (dif[r] + x) : (0));       }       printf( %lld n ,              ((a[1] + d) % 2) ? (((a[1] + d) >> 1) + 1) : (a[1] + d) >> 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   constexpr int N = 2e5 + 5;   int t, a, b, p;   string s;   void Solve() {     cin >> t;     while (t--) {       cin >> a >> b >> p >> s;       s.pop_back();       vector<ll> suf;       suf.resize(s.size());       char last =  0 ;       for (int i = s.size() - 1; i >= 0; i--) {         if (s[i] != last) suf[i] = (s[i] ==  A  ? a : b);         last = s[i];       }       for (int i = suf.size() - 2; i >= 0; i--) suf[i] += suf[i + 1];       int id = 0;       while (id < suf.size() && suf[id] > p) id++;       cout << id + 1 <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     Solve();     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 1e4;   struct edg {     int now, to, val;   } ed[N];   struct edge {     int to, next;   } e[N];   int ehead[N], ecnt;   inline void add_edge(int now, int to) {     ecnt++;     e[ecnt].to = to;     e[ecnt].next = ehead[now];     ehead[now] = ecnt;   }   int n, m, left, rig, mid;   int pos[N], ans[N], acnt, pcnt;   void dfs(int now) {     pos[now] = 1;     for (int i = ehead[now]; i; i = e[i].next)       if (pos[e[i].to] == 0) dfs(e[i].to);     pos[now] = ++pcnt;   }   inline bool check(int lim) {     ecnt = acnt = 0;     memset(ehead, 0, sizeof(ehead));     memset(pos, 0, sizeof(pos));     for (int i = 1; i <= m; i++)       if (ed[i].val > lim) add_edge(ed[i].now, ed[i].to);     for (int i = 1; i <= n; i++)       if (!pos[i]) dfs(i);     for (int i = 1; i <= m; i++)       if (pos[ed[i].now] < pos[ed[i].to])         if (ed[i].val > lim)           return false;         else           ans[++acnt] = i;     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &ed[i].now, &ed[i].to, &ed[i].val);     rig = 1e9;     while (left != rig) {       mid = (left + rig) >> 1;       if (check(mid))         rig = mid;       else         left = mid + 1;     }     check(left);     printf( %d %d n , left, acnt);     for (int i = 1; i <= acnt; i++) printf( %d  , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e5 + 10;   int beg[N];   int nxt[N];   int to[N];   int tot;   int a[N];   void add(int x, int y) {     ++tot;     nxt[tot] = beg[x];     to[tot] = y;     beg[x] = tot;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       add(x, i);     }     int ans = 0;     for (int i = 1; i <= m; ++i) {       int siz = 0;       for (int j = beg[i]; j; j = nxt[j]) a[++siz] = to[j];       if (siz == 0) continue;       reverse(a + 1, a + 1 + siz);       for (int r = 1, l = 1; r <= siz; ++r) {         for (; l < r && a[r] - a[l] + 1 > k + r - l + 1; ++l)           ;         ans = max(ans, r - l + 1);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, p, x;     cin >> n >> k >> p;     std::vector<int> even, odd;     for (int i = 0; i < n; ++i) {       cin >> x;       if (x % 2)         odd.emplace_back(x);       else         even.emplace_back(x);     }     if (odd.size() < k - p || (odd.size() - k - p) % 2 != 0) {       cout <<  NO ;       return 0;     }     if ((even.size() + (odd.size() - (k - p)) / 2) < p) {       cout <<  NO  <<   n ;       return 0;     }     cout <<  YES  <<   n ;     long long cnt = 0;     if (k - p) {       while (even.size() > 0 && cnt != p) {         cout << 1 <<     << even.back() <<   n ;         even.pop_back();         cnt++;       }       while (odd.size() > 0 && cnt != p) {         cout << 2 <<     << odd.back() <<    ;         odd.pop_back();         cout << odd.back() <<   n ;         odd.pop_back();         cnt++;       }       for (int i = 0; i < k - p - 1; i++) {         vector<int> ans;         while (even.size() > 0) {           ans.emplace_back(even.back());           even.pop_back();         }         ans.emplace_back(odd.back());         odd.pop_back();         cout << ans.size() <<    ;         for (auto i : ans) {           cout << i <<    ;         }         cout <<   n ;       }       vector<int> ans;       while (odd.size() > 0) {         ans.emplace_back(odd.back());         odd.pop_back();       }       while (even.size() > 0) {         ans.emplace_back(even.back());         even.pop_back();       }       cout << ans.size() <<    ;       for (auto i : ans) {         cout << i <<    ;       }       cout <<   n ;     } else {       vector<int> ans;       for (int i = 0; i < p - 1; i++) {         if (even.size() > 0) {           cout << 1 <<     << even.back() <<   n ;           even.pop_back();         } else {           cout << 2 <<     << odd.back() <<    ;           odd.pop_back();           cout << odd.back() <<    ;           odd.pop_back();         }       }       while (even.size() > 0) {         ans.emplace_back(even.back());         even.pop_back();       }       while (odd.size()) {         ans.emplace_back(odd.back());         odd.pop_back();       }       cout << ans.size() <<    ;       for (auto I : ans) {         cout << I <<    ;       }     }   }