malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:134217728 )   using namespace std;   char buf[2];   vector<int> sign;   int n;   int main() {     sign.push_back(1);     scanf( %s , buf);     while (1) {       scanf( %s , buf);       if (buf[0] ==  = ) break;       sign.push_back(buf[0] ==  +  ? 1 : -1);       scanf( %s , buf);     }     scanf( %d , &n);     int MIN = 0;     int MAX = 0;     vector<int> res;     for (int i = 0; i < sign.size(); ++i) {       if (sign[i] == 1) {         MIN++;         MAX += n;         res.push_back(n);       } else {         MIN -= n;         MAX--;         res.push_back(1);       }     }     if (MIN <= n && n <= MAX) {       printf( Possible n );       int need = MAX - n;       for (int i = 0; i < res.size(); ++i) {         if (sign[i] == 1) {           int d = min(need, res[i] - 1);           res[i] -= d;           need -= d;         } else {           int d = min(need, n - res[i]);           res[i] += d;           need -= d;         }       }       printf( %d , res[0]);       for (int i = 1; i < res.size(); ++i) {         if (sign[i] == 1)           printf(  +  );         else           printf(  -  );         printf( %d , res[i]);       }       printf(  = %d n , n);     } else       printf( Impossible n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   string name[MAXN], surname[MAXN];   bool u[MAXN];   int n;   int x1[30], x2[30];   int Getn() {     int res = 0;     for (int i = 0; i < 26; i++) res += min(x1[i], x2[i]);     return res;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> name[i];     for (int i = 1; i <= n; i++) cin >> surname[i];     sort(name + 1, name + n + 1);     sort(surname + 1, surname + n + 1);     for (int i = 1; i <= n; i++) x1[name[i][0] -  A ]++;     for (int i = 1; i <= n; i++) x2[surname[i][0] -  A ]++;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (!u[j]) {           int c = Getn();           x1[name[i][0] -  A ]--;           x2[surname[j][0] -  A ]--;           if (Getn() != c - (name[i][0] == surname[j][0])) {             x1[name[i][0] -  A ]++;             x2[surname[j][0] -  A ]++;             continue;           }           u[j] = true;           cout << name[i] <<     << surname[j];           if (i != n)             cout <<  ,  ;           else             cout << endl;           break;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   unordered_map<int, int> f[N];   int n, m, k, ans, p[N], sx[N], sy[N];   inline int sol(int x, int y) {     if (f[x].count(y)) return f[x][y];     int t;     printf( ? %d %d n , x, y), fflush(stdout), scanf( %d , &t);     return f[x][y] = t;   }   inline vector<int> solve(int n, int m, vector<int>& x, vector<int>& y) {     if (n >= m) {       if (n == 1) {         vector<int> z;         z.resize(1), z[0] = 1;         ans = min(ans, sol(x[0], y[0]));         return z;       } else {         vector<int> a, b;         for (int i = 0; i < n; i += 2) a.push_back(x[i]);         for (int i = 0; i < m; i++) b.push_back(y[i]);         vector<int> z = solve((n + 1) / 2, m, a, b), q;         z.push_back(m);         int k = 0;         for (int i = 0; i < n; i++) {           if (i % 2 == 0)             q.push_back(z[k++]);           else {             int sum = 1000000001, pos = 0;             for (int c = z[k - 1]; c <= z[k]; c++) {               int g = sol(x[i], y[c - 1]);               if (sum > g) sum = g, pos = c;             }             q.push_back(pos), ans = min(ans, sum);           }         }         return q;       }     } else {       int l = 1;       sx[l] = 1, sy[l] = 1;       for (int i = 2; i <= m; i++) {         while (l > 0) {           int a = sol(x[sx[l] - 1], y[sy[l] - 1]),               b = sol(x[sx[l] - 1], y[i - 1]);           if (a > b)             l--;           else             break;         }         if (sx[l] != n) l++, sx[l] = sx[l - 1] + 1, sy[l] = i;       }       vector<int> a, b, w;       for (int i = 0; i < n; i++) a.push_back(x[i]);       for (int i = 1; i <= l; i++) b.push_back(y[sy[i] - 1]), w.push_back(sy[i]);       vector<int> z = solve(n, l, a, b), q;       for (int i = 0; i < w.size(); i++) p[i + 1] = w[i];       for (int i = 0; i < z.size(); i++) q.push_back(p[z[i]]);       return q;     }   }   int main() {     cin >> n >> m;     vector<int> a, b;     a.resize(n), b.resize(m), ans = 1000000000;     for (int i = 0; i < n; i++) a[i] = i + 1;     for (int i = 0; i < m; i++) b[i] = i + 1;     solve(n, m, a, b);     printf( ! %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> s;     s =  ?  + s +  ? ;     int c = 0;     bool flag = true;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ? ) {         c++;         if (s[i - 1] == s[i + 1] || s[i - 1] ==  ?  || s[i + 1] ==  ? ) {           flag = false;         }       }       if (s[i] == s[i - 1] && s[i] !=  ? ) {         flag = true;         break;       }     }     cout << (c == 0 || flag ?  NO  :  YES ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x[n], y[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     if (n == 1) {       cout << -1 << endl;     } else if (n == 2) {       if (x[0] != x[1] && y[0] != y[1]) {         int a = fabs(x[0] - x[1]), b = fabs(y[0] - y[1]);         cout << a * b << endl;       } else {         cout << -1 << endl;       }     } else if (n == 3 || n == 4) {       sort(x, x + n);       sort(y, y + n);       int a = fabs(x[0] - x[n - 1]), b = fabs(y[0] - y[n - 1]);       cout << a * b << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t, n, i, j, k, l, r, minn, maxx, ans, x, y;     cin >> t;     while (t--) {       cin >> n;       cin >> maxx >> minn;       for (i = 1; i < n; i++) {         cin >> x >> y;         maxx = max(maxx, x);         minn = min(minn, y);       }       if (maxx <= minn)         ans = 0;       else         ans = maxx - minn;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q;   int main(void) {     cin >> q;     while (q--) {       long long l, r, ans = 0, num = 0;       cin >> l >> r;       num = r - l + 1;       if (r & 1) {         ans -= num / 2;         if (num & 1) ans -= l;       } else {         ans += num / 2;         if (num & 1) ans += l;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   #define rep(i,a,b) for(int i = (a); i < (b); ++i)   #define rrep(i,a,b) for(int i = (b); i --> (a);)   #define sz(v) int(v.size())   using namespace std;      string inf, zero;      string add(string x, string y, int init){    string res(sz(x),  ? );    int todo = init;    rrep(i,0,sz(x)){     todo += x[i] + y[i] - 2 *  0 ;     res[i] = todo % 2 +  0 ;     todo /= 2;    }    if(todo) return inf;    return res;   }      int main(){    int n, b;    cin >> n >> b;    inf = string(b,  1 );    zero = string(b,  0 );       vector<string> fibs = {zero, zero}; // fibonacci numbers minus one    while(fibs.back() < inf)     fibs.push_back(add(fibs.back(), fibs[sz(fibs)-2], 1));    int todo = sz(fibs)-1;    deque<pair<int, bool>> ls;    rep(i,0,n) ls.push_back({i+1, true});    string lb = zero; // current lower bound    while(!ls.empty()){     string ans;     if(add(lb, fibs[todo], 0) == inf) ans =  no ;     else { cout << ls.back().first <<     << add(lb, fibs[max(0, todo)], 0) << endl;            cin >> ans; }      if(ans ==  yes ){      lb = add(lb, fibs[todo], 1);      while(!ls.empty() && ls[0].second){       ls.pop_front();       todo += 2;      }      if(ls.empty()) break;      ls[0].second = true;     } else {      ls.push_front({ls.back().first, false});      ls.pop_back();     }     if(--todo <= 0){      todo += ls[0].second ? 2 : 1;      ls.pop_front();     }    }    cout << 0 <<     << lb << endl;   }
#include <bits/stdc++.h>   using namespace std;   char _;   const long long maxN = 200 * 1000 + 5;   const long long maxM = 5000 + 5;   const long long mod = 1000 * 1000 * 1000 + 7;   const long long base = 701;   const long long SQ = 500;   const long long maxL = 20;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long s, x;     cin >> s >> x;     if (s < x) {       cout << 0 << endl;       return 0;     }     long long ans = 1;     for (long long i = 0; i < 40; i++)       if (x >> i & 1) ans *= 2;     long long carry = 0;     for (long long i = 40; i >= 0; i--) {       long long g = (s >> i & 1), f = (x >> i & 1);       if (carry == 0 && f == 0 && g == 0) continue;       if (carry == 0 && f == 0 && g == 1) {         carry = 1;         continue;       }       if (carry == 0 && f == 1 && g == 0) {         cout << 0 << endl;         return 0;       }       if (carry == 0 && f == 1 && g == 1) continue;       if (carry == 1 && f == 0 && g == 0) {         carry = 0;         continue;       }       if (carry == 1 && f == 0 && g == 1) continue;       if (carry == 1 && f == 1 && g == 0) continue;       if (carry == 1 && f == 1 && g == 1) {         cout << 0 << endl;         return 0;       }     }     if (s == x) ans -= 2;     if (carry)       cout << 0 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int N;     cin >> N;     int c;     cin >> c;     int A[N];     A[0] = 0;     int B[N];     B[0] = 0;     for (int i = 1; i < N; i++) cin >> A[i];     for (int i = 1; i < N; i++) cin >> B[i];     int f[N][2];     f[0][0] = 0;     f[0][1] = c;     for (int j = 1; j < N; j++) {       f[j][0] = min(f[j - 1][0], f[j - 1][1]) + A[j];       f[j][1] = min(f[j - 1][0] + c, f[j - 1][1]) + B[j];     }     for (int i = 0; i < N - 1; i++) cout << min(f[i][0], f[i][1]) <<    ;     cout << min(f[N - 1][0], f[N - 1][1]) << endl;     return 0;   }
#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ull = std::uint64_t;   using ll = std::int64_t;   using llf = long double;   ul n, m, k;   const ul maxn = 2e5;   const ul base = 998244353;   ul plus(ul a, ul b) { return a + b < base ? a + b : a + b - base; }   ul plus(ul a, ul b, ul c) { return plus(plus(a, b), c); }   ul minus(ul a, ul b) { return a < b ? a + base - b : a - b; }   ul mul(ul a, ul b) { return ull(a) * ull(b) % base; }   ul mul(ul a, ul b, ul c) { return mul(mul(a, b), c); }   ul mul(ul a, ul b, ul c, ul d) { return mul(mul(a, b, c), d); }   void exgcd(li a, li b, li& x, li& y) {     if (b) {       exgcd(b, a % b, y, x);       y -= a / b * x;     } else {       x = 1;       y = 0;     }   }   ul inverse(ul a) {     li x, y;     exgcd(a, base, x, y);     return x < 0 ? x + li(base) : x;   }   ul pow(ul a, ul b) {     ul ret = 1;     while (b) {       if (b & 1) {         ret = mul(a, ret);       }       b >>= 1;       a = mul(a, a);     }     return ret;   }   ul h[maxn + 1];   ul fac[maxn + 1];   ul fiv[maxn + 1];   ul twopow[maxn + 1];   ul bi(ul a, ul b) { return mul(fac[a], fiv[b], fiv[a - b]); }   ul g(ul a) {     ul ret = mul(base + 1 >> 1, twopow[a]);     if (~a & 1) {       ret = minus(ret, mul(base + 1 >> 1, bi(a, a >> 1)));     }     return ret;   }   int main() {     fac[0] = 1;     twopow[0] = 1;     for (ul i = 1; i <= maxn; ++i) {       fac[i] = mul(fac[i - 1], i);       twopow[i] = plus(twopow[i - 1], twopow[i - 1]);     }     fiv[maxn] = inverse(fac[maxn]);     for (ul i = maxn; i; --i) {       fiv[i - 1] = mul(fiv[i], i);     }     std::scanf( %u%u , &n, &k);     k %= base;     for (ul i = 1; i <= n; ++i) {       std::scanf( %u , &h[i]);     }     for (ul i = 1; i <= n; ++i) {       m += h[i] != h[i % n + 1];     }     ul ans = 0;     for (ul a = 0; a <= m; ++a) {       ans = plus(ans, mul(bi(m, a), pow(minus(k, 2), m - a), g(a)));     }     ans = mul(ans, pow(k, n - m));     std::printf( %u n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> s;   map<int, int> mm;   int a[500005];   int main() {     int n, m, d;     cin >> n >> m >> d;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       s.insert(k);       a[i] = k;     }     set<int>::iterator it1, it2, it3;     int sum = 0;     for (it1 = s.begin(); it1 != s.end(); it1++) {       sum++;       mm[*it1] = sum;       it2 = it1;       while (s.upper_bound((*it2) + d) != s.end()) {         it3 = s.upper_bound((*it2) + d);         mm[*it3] = sum;         it2 = it3;         s.erase(it3);       }     }     cout << sum << endl;     for (int i = 0; i < n; i++) {       cout << mm[a[i]] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   const int MAXM = 1100;   const int MAXK = 100100;   int n, m, k, len[MAXK], max_len[MAXN][MAXM][4];   int mm[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   char mmap[MAXN][MAXM], dir[MAXK], direction[256];   vector<pair<int, int> > possible;   vector<char> sol;   int get_max_len(int r, int c, int d) {     if (max_len[r][c][d] != -1) return max_len[r][c][d];     if (mmap[r][c] ==  # ) return -1;     int &ml = max_len[r][c][d];     ml = 0;     int nr = r + mm[d][0];     int nc = c + mm[d][1];     ml += 1 + get_max_len(nr, nc, d);     return ml;   }   bool solve(int r, int c) {     for (int i = 0; i < k; i++) {       int d = direction[(int)dir[i]];       int maxd = get_max_len(r, c, d);       if (maxd < len[i]) return false;       r += mm[d][0] * len[i];       c += mm[d][1] * len[i];     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     direction[ N ] = 1;     direction[ S ] = 0;     direction[ E ] = 2;     direction[ W ] = 3;     cin >> n >> m;     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= m + 1; j++) {         if (i == 0 || i > n || j == 0 || j > m)           mmap[i][j] =  # ;         else           cin >> mmap[i][j];         if ( A  <= mmap[i][j] && mmap[i][j] <=  Z )           possible.push_back(make_pair(i, j));         max_len[i][j][0] = -1;         max_len[i][j][1] = -1;         max_len[i][j][2] = -1;         max_len[i][j][3] = -1;       }     cin >> k;     for (int i = 0; i < k; i++) cin >> dir[i] >> len[i];     for (int i = 0; i < (int)possible.size(); i++) {       int r = possible[i].first;       int c = possible[i].second;       if (solve(r, c)) sol.push_back(mmap[r][c]);     }     if (sol.empty())       cout <<  no solution  << endl;     else {       sort(sol.begin(), sol.end());       for (int i = 0; i < (int)sol.size(); i++) cout << sol[i];       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, num = 1, mul;     cin >> n;     string s =  codeforces ;     int ln = s.length(), a[12] = {0};     for (long long int i = 2; i <= 100; i++) {       long long int curr = pow(i, 10ll);       if (curr >= n) {         for (int j = 0; j < 10; j++) {           a[j] = i - 1;           num *= (i - 1);         }         mul = i;         break;       }     }     int pos = 0;     while (num < n) {       num /= (mul - 1);       num *= mul;       a[pos] = mul;       pos++;     }     for (int i = 0; i < 10; i++) {       for (int j = 0; j < a[i]; j++) cout << s[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD9 = 1e9 + 7;   const int MOD91 = 1e9 + 9;   const long long MOD12 = 1e12 + 39LL;   const long long MOD15 = 1e15 + 37LL;   const int INF = 1e9;   const int base = 1e9;   const int MAX = 2e5;   const long double EPS = 1e-10;   int n;   int a[200000];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     sort(a, a + n);     if (a[0] == a[n - 1] && a[0] == 1) {       for (int i = 0; i < n - 1; ++i) {         cout << a[i] <<    ;       }       cout << 2;       return 0;     }     cout << 1 <<    ;     for (int i = 0; i < n - 1; ++i) {       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int solve();   int main() { solve(); }   int solve() {     string s;     vector<int> cnt(26);     cin >> s;     int ncnt = 0;     for (int i = 0; i < s.size(); ++i) ++cnt[s[i] -  a ];     for (int i = 0; i < 26; ++i) ncnt += (cnt[i] & 1);     while (ncnt > 1) {       for (int i = 25; i >= 0; --i) {         for (int j = 0; j < i; ++j) {           if ((cnt[i] & 1) && (cnt[j] & 1)) {             ncnt -= 2;             ++cnt[j];             --cnt[i];             break;           }         }       }     }     for (int i = 0; i < 26; ++i) {       for (int j = 0; j < cnt[i] / 2; ++j) {         cout << (char)(i +  a );       }     }     if (ncnt) {       for (int i = 0; i < 26; ++i) {         if (cnt[i] & 1) cout << (char)(i +  a );       }     }     for (int i = 25; i >= 0; --i) {       for (int j = 0; j < cnt[i] / 2; ++j) {         cout << (char)(i +  a );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 333333;   const int INF = 2000000000;   int n, m, k, a[M];   inline int read() {     char c = getchar();     int ans = 0;     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 )       ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();     return ans;   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= m; i++) a[i] = INF;     for (int i = 1, x, c; i <= n; i++) {       x = read(), c = read();       a[x] = min(a[x], c);     }     int ans = 0;     for (int i = 1; i <= m; i++) ans += a[i];     printf( %d , min(ans, k));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, ans;   string a;   int main() {     cin >> a;     ans = a.size();     long long t = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  ) )         t--;       else         t++;       if (t < 0) {         t = 0;         ans--;       }     }     cout << ans - t << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[10000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int n, k;     string s;     cin >> n >> k;     cin >> s;     int cnt = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] == s[i - 1]) {         cnt++;       } else {         ans[s[i - 1]] += cnt / k;         cnt = 1;       }     }     ans[s[s.size() - 1]] += cnt / k;     int mx = -1;     for (char i =  a ; i <=  z ; i++) {       mx = max(ans[i], mx);     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long k, na;   };   const long maxn = 100001;   node a[maxn];   long n, b[maxn];   int qsort(long low, long high) {     long i = low, j = high, x = a[(i + j) / 2].k;     while (i < j) {       while (a[i].k < x) i++;       while (a[j].k > x) j--;       if (i <= j) {         swap(a[i], a[j]);         i++;         j--;       }     }     if (i < high) qsort(i, high);     if (j > low) qsort(low, j);     return 0;   }   void init() {     cin >> n;     for (long i = 1; i <= n; i++) {       cin >> a[i].k;       a[i].na = i;     }     qsort(1, n);   }   void work() {     memset(b, 0, sizeof(b));     for (long i = 1; i <= n; i++) b[a[i].k] += 1;     int bj = 1;     for (long i = 2; i <= a[n].k; i++)       if (b[i] > b[i - 1]) bj = 0;     if (bj) {       cout << b[1] << endl;       long s = 0;       for (long i = 1; i <= n; i++) {         if ((i == 1) || (a[i].k == a[i - 1].k))           s++;         else           s = 1;         b[a[i].na] = s;       }       for (long i = 1; i <= n; i++) {         cout << b[i];         if (i != n) cout <<    ;       }       cout << endl;     } else       cout << -1 << endl;   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, w[1000999];   int arr[1009999];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);       arr[w[i]]++;     }     for (int i = 0; i < 1000099; i++) {       arr[i + 1] += arr[i] / 2;       arr[i] = arr[i] % 2;     }     int ans = 0;     for (int i = 0; i < 1000099; i++) {       if (arr[i] >= 1) {         ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 5;   const int mod = 26;   long long qp(long long a, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * a % mod;       a = a * a % mod;       n >>= 1;     }     return res;   }   template <class T>   inline bool scan(T &ret) {     char c;     int sgn;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void out(T x) {     if (x > 9) out(x / 10);     putchar(x % 10 +  0 );   }   int n, m;   vector<pair<int, int> > mp[maxn];   int flag[maxn];   int res[maxn];   int main() {     scan(n), scan(m);     int x;     int flagt = 0, tmp = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scan(x);         mp[i].emplace_back(x, j);       }       sort(mp[i].begin(), mp[i].end());       mp[i].erase(unique(mp[i].begin(), mp[i].end(),                          [](pair<int, int> &x, pair<int, int> &y) {                            return x.first == y.first;                          }),                   mp[i].end());       res[i] = mp[i][0].second;       if (mp[i].size() == 1) {         flag[i] = 1;         tmp ^= mp[i][0].first;       } else {         if (flagt == 0)           flagt = i;         else {           tmp ^= mp[i][0].first, flag[i] = 1;         }       }     }     for (int i = 0; i < mp[flagt].size(); ++i) {       if ((tmp ^ mp[flagt][i].first) != 0) {         res[flagt] = mp[flagt][i].second;         tmp ^= mp[flagt][i].first;         flagt = -1;         break;       }     }     if (flagt == -1 || (flagt == 0 && tmp)) {       puts( TAK );       for (int i = 1; i <= n; ++i) {         printf( %d  , res[i]);       }     } else {       puts( NIE );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, -1, 0};   int dy[] = {1, 0, 0, -1};   long double PI = 3.14159265358979323846264338327950;   pair<int, int> p[12000002];   int a[12000002], b[12000002];   int m, n, k;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     for (int i = 1, x; i <= n; i++) {       cin >> x;       a[x]++;       if (a[x] > k) {         cout << -1;         return 0;       }     }     for (int i = 1, x; i <= m; i++) {       cin >> x;       p[i] = {x, i};     }     sort(p + 1, p + 1 + m);     int ch = 0;     int res = 0;     for (int i = 1; i <= m; i++) {       for (; a[ch] == k; ch++)         ;       if (ch > p[i].first)         continue;       else {         res++;         b[res] = p[i].second, a[ch]++;       }     }     cout << res <<   n ;     for (int i = 1; i <= res; i++) cout << b[i] <<    ;     return 0;   }