malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, a, counter = 0, ar[100000];     map<char, int> mp;     mp[ 6 ] = 1, mp[ 7 ] = 2, mp[ 8 ] = 3, mp[ 9 ] = 4, mp[ T ] = 5;     mp[ J ] = 6, mp[ Q ] = 7, mp[ K ] = 8, mp[ A ] = 9;     string str1, str2;     char trump;     cin >> trump;     cin >> str1 >> str2;     if (str1[1] == trump && str1[1] != str2[1])       cout <<  YES  << endl;     else if (str1[1] == str2[1] && mp[str1[0]] > mp[str2[0]])       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool y[200005];   long long n, m, k, j, i, p[2000005], q[2000005], haj[2000005], s, sum;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     p[1] = 0;     sum = n * (n + 1) / 2;     for (i = 1; i < n; i++) {       haj[i] = i;       cin >> q[i];       p[i + 1] = p[i] + q[i];       s += p[i + 1];     }     haj[n] = n;     sum -= s;     if (sum % n != 0) {       cout << -1 << endl;       return 0;     } else {       for (i = 1; i <= n; i++) p[i] += sum / n;       for (i = 1; i <= n; i++) {         if (p[i] < 0 || p[i] > n) {           cout << -1 << endl;           return 0;         } else if (y[p[i]]) {           cout << -1 << endl;           return 0;         } else {           y[p[i]] = true;         }       }       for (i = 1; i <= n; ++i) {         cout << p[i] << endl;       }       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ;   const double eps = 1e-8;   const int mod = 1000000007;   const int maxn = 1e5 + 7;   const double pi = acos(-1);   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f;   int n;   long long p;   struct node {     long long a, b;   } num[maxn];   bool check(double x) {     double ans = 0;     for (int i = 1; i <= n; i++) {       if (x * num[i].a - num[i].b > eps) {         ans += x * num[i].a - num[i].b;       }     }     return x * p - ans > eps;   }   int main() {     scanf( %d%lld , &n, &p);     long long sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &num[i].a, &num[i].b);       sum += num[i].a;     }     if (sum <= p) {       printf( -1 n );       return 0;     }     double ub = INF, lb = 0, mid;     for (int i = 0; i <= 100; i++) {       mid = (ub + lb) / 2;       if (check(mid))         lb = mid;       else         ub = mid;     }     printf( %.7f n , ub);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-11;   int countbit(int n) { return (n == 0) ? 0 : 1 + countbit(n & (n - 1)); }   int lowbit(int n) { return n & (n ^ (n - 1)); }   string toString(long long v) {     ostringstream sout;     sout << v;     return sout.str();   }   string toString(int v) {     ostringstream sout;     sout << v;     return sout.str();   }   int Rand16() { return rand(); }   int Rand32() { return rand() * rand(); }   double DRand() { return (double)rand() / RAND_MAX; }   int RandRange(int f, int r) { return f + (int)(DRand() * (r - f) + 0.5); }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     int i, j;     int ans = 0;     for (i = 2; i < n; i++) {       int tmp = n;       while (tmp) ans += tmp % i, tmp /= i;     }     int d = gcd(ans, n - 2);     int A = ans / d;     int B = (n - 2) / d;     cout << A <<  /  << B << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int N, Q;     scanf( %d%d , &N, &Q);     int et[N + 1];     memset(et, -1, sizeof(et));     while (Q-- > 0) {       int t, k, d;       scanf( %d%d%d , &t, &k, &d);       int ans = -1;       int as = 0;       for (int i = 1; i <= N; i++) {         if (t > et[i]) et[i] = -1;         if (et[i] == -1) as++;       }       if (as >= k) {         ans = 0;         for (int i = 1; i <= N && k > 0; i++) {           if (et[i] == -1) {             ans += i;             k--;             et[i] = t + d - 1;           }         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int seq[100];   void display(const int n) {     for (int i = 0; i < n; ++i) printf( %d  , seq[i]);     putchar(  n );   }   int compute_sum(const int n) {     int sum = 0;     for (int i = 0; i < n; ++i) {       int x = seq[i];       for (int j = i; j < n; ++j) {         x = min(x, seq[j]);         sum += x;       }     }     return sum;   }   bool solve(const int n, int m) {     for (int i = 0; i < n; ++i) seq[i] = i + 1;     int best = 0;     do {       const int sum = compute_sum(n);       best = max(best, sum);     } while (next_permutation(seq, seq + n));     for (int i = 0; i < n; ++i) seq[i] = i + 1;     do {       const int sum = compute_sum(n);       if (sum == best) {         if (--m == 0) {           display(n);           return true;         }       }     } while (next_permutation(seq, seq + n));     return false;   }   void s(const long long x, const long long y, const int first) {     printf( visiting with x=%lld, y=%lld, first=%d n , x, y, first);     if (x <= 0) return;     assert(y < x);     long long delta = max(1LL, x >> 1);     long long index = 0;     int movements = 0;     for (;;) {       printf( index = %lld, delta = %lld, movements = %d n , index, delta,              movements);       if (index + delta <= y) {         movements += 1;         index += delta;       } else {         cout << first + movements <<     << endl;         s(x >> 1, y - index, first + 1);         break;       }       delta = max(1LL, delta >> 1);     }   }   vector<int> v;   void compute(const int l, const int r, long long m) {     if (l > r) return;     if (l == r) {       v.push_back(l);       return;     }     const long long x = 1LL << (r - l);     long long delta = max(1LL, x >> 1);     int movements = 0;     for (;;) {       const long long new_m = m - delta;       if (new_m >= 0) {         m = new_m;         movements += 1;         delta = max(1LL, delta >> 1);       } else {         const int first_digit = l + movements;         v.push_back(first_digit);         compute(first_digit + 1, r, m);         for (int i = l + movements - 1; i >= l; --i) v.push_back(i);         break;       }     }   }   void solve_fast(const int n, long long m) {}   void test() {     for (int n = 1; n <= 5; ++n) {       for (int m = 1; m <= 100; ++m) {         if (m <= 1LL << (n - 1)) {           if (solve(n, m)) {             v.clear();             compute(1, n, m - 1);             for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);             putchar(  n );           }         }       }       putchar(  n );     }   }   void run() {     int n;     long long m;     cin >> n >> m;     v.clear();     compute(1, n, m - 1);     for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]);     putchar(  n );   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   const int inf = 1039074182;   using namespace std;   int n, r, c;   string word[1000005];   int len[1000005];   int nxt[1000005];   pair<int, int> st[1000005][22];   int sum[1000005];   int calc(int start) {     int res = 0;     for (int i = 0; i < 22; i++) {       if ((1 << i) & r) {         res += st[start][i].second;         start = st[start][i].first;       }     }     return res;   }   void print(int start) {     for (int i = 0; i < r; i++) {       if (start == n) break;       for (int j = start; j < nxt[start]; j++) {         cout << word[j];         if (j != nxt[start] - 1) cout <<    ;       }       cout << endl;       start = nxt[start];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> r >> c;     for (int i = 0; i < n; i++) {       cin >> word[i];       len[i] = word[i].size();     }     sum[0] = len[0] + 1;     for (int i = 1; i < n; i++) {       sum[i] = sum[i - 1] + len[i] + 1;     }     for (int i = 0, j = 0; i < n; i++) {       while (j < n && sum[j] - (i ? sum[i - 1] : 0) - 1 <= c) j++;       nxt[i] = j;     }     for (int i = 0; i < n; i++) {       st[i][0] = make_pair(nxt[i], nxt[i] - i);     }     for (int i = 0; i < 22; i++) {       st[n][i] = make_pair(n, 0);     }     for (int k = 1; k < 22; k++) {       for (int i = 0; i < n; i++) {         st[i][k].first = st[st[i][k - 1].first][k - 1].first;         st[i][k].second =             st[i][k - 1].second + st[st[i][k - 1].first][k - 1].second;       }     }     int res = -1, maxk = -1;     int temp;     for (int i = 0; i < n; i++) {       temp = calc(i);       if (temp > res) {         res = temp;         maxk = i;       }     }     print(maxk);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string a, b, c, d, e;   vector<vector<int> > vals;   vector<vector<int> > forms(1);   map<string, int> getind;   int doop(int left, int right, int op) {     if (op == 2) return left ^ right;     if (op == 3)       return left & right;     else       return left | right;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     vals.resize(1, vector<int>(m, 0));     getind[ ? ] = 0;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       getind[a] = vals.size();       vals.resize(vals.size() + 1);       forms.resize(forms.size() + 1);       if (c[0] !=  1  && c[0] !=  0 ) {         cin >> d >> e;         int first = getind[c];         int sec = getind[e];         int op = 2;         if (d ==  AND )           op = 3;         else if (d ==  OR )           op = 4;         forms[forms.size() - 1].push_back(first);         forms[forms.size() - 1].push_back(op);         forms[forms.size() - 1].push_back(sec);         for (int j = 0; j < m; j++) {           vals[vals.size() - 1].push_back(doop(vals[first][j], vals[sec][j], op));         }       } else {         for (int j = 0; j < m; j++) {           if (c[j] ==  1 )             vals[vals.size() - 1].push_back(1);           else             vals[vals.size() - 1].push_back(0);         }       }     }     vector<int> best(m, 0);     vector<int> worst(m, 0);     for (int i = 0; i < m; i++) {       int curcnt = 0;       int rescnt = 0;       for (int j = 1; j <= n; j++) {         if (forms[j].size() > 0) {           curcnt += vals[j][i];         }       }       vals[0][i] = 1;       for (int j = 1; j <= n; j++) {         if (forms[j].size() > 0) {           int first = forms[j][0];           int sec = forms[j][2];           int op = forms[j][1];           int res = doop(vals[first][i], vals[sec][i], op);           vals[j][i] = res;           rescnt += res;         }       }       if (rescnt > curcnt) best[i] = 1;       if (rescnt < curcnt) worst[i] = 1;     }     for (int i = 0; i < m; i++) {       cout << worst[i];     }     cout <<   n ;     for (int i = 0; i < m; i++) {       cout << best[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r, c;   int main() {     int n;     scanf( %d , &n);     while (n--) {       scanf( %d %d , &r, &c);       for (int i = 0; i < r; i++) {         for (int j = 0; j < c; j++)           if (i == r - 1 && j == c - 1)             printf( W );           else             printf( B );         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2 * (100000) + 5;   int a[MAXN], b[MAXN];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     int res = 0;     int j = 0;     for (int i = 0; i < n && j < n; ++i) {       while (j < n && a[i] != b[j]) {         j++;         res++;       }       j++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long w[400005], sum[400005][21], f[400005][21], mx[400005][21];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(sum, 0x3f, sizeof(sum));     int q;     cin >> q;     long long last = 0;     int tot = 1;     f[1][0] = 1, sum[1][0] = 0;     while (q--) {       long long op, p, q;       cin >> op >> p >> q;       p ^= last, q ^= last;       if (op == 1) {         ++tot;         w[tot] = q, sum[tot][0] = q, f[tot][0] = tot, mx[tot][0] = q;         if (q <= w[p]) {           f[tot][1] = p;           sum[tot][1] = w[p] + q;           mx[tot][1] = max(q, w[p]);           for (int i = 2; i <= 20; ++i) {             f[tot][i] = f[f[f[tot][i - 1]][1]][i - 1];             if (!f[tot][i]) break;             mx[tot][i] = max(mx[f[f[tot][i - 1]][1]][i - 1], mx[tot][i - 1]);             sum[tot][i] = sum[f[f[tot][i - 1]][1]][i - 1] + sum[tot][i - 1];           }         } else {           for (int i = 20; i >= 0; --i) {             if (!f[p][i]) continue;             if (mx[p][i] < q) p = f[f[p][i]][1];           }           if (p && q <= w[p]) {             f[tot][1] = p;             sum[tot][1] = w[p] + q;             mx[tot][1] = max(q, w[p]);             for (int i = 2; i <= 20; ++i) {               f[tot][i] = f[f[f[tot][i - 1]][1]][i - 1];               if (!f[tot][i]) break;               mx[tot][i] = max(mx[f[f[tot][i - 1]][1]][i - 1], mx[tot][i - 1]);               sum[tot][i] = sum[f[f[tot][i - 1]][1]][i - 1] + sum[tot][i - 1];             }           }         }       } else {         long long ans = 0, tmp = 0;         for (int i = 20; i >= 0; --i) {           if (!f[p][i]) continue;           if (sum[p][i] + tmp <= q) {             tmp += sum[p][i];             ans += 1 << i;             p = f[f[p][i]][1];           }           if (!p) break;         }         cout << (last = ans) <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long n, long long m) {     long long x, y;     if (n > m) {       y = n;       x = m;     } else {       y = m;       x = n;     }     if (y % x == 0)       return x;     else {       return gcd(x, y % x);     }   }   int main() {     long long n;     cin >> n;     string str;     cin >> str;     long long m = n;     for (long long i = 0; i < n; i += 2) {       if (m - 2 == 1) {         cout << str[i] << str[i + 1] << str[i + 2];         break;       } else {         cout << str[i] << str[i + 1];         if (m - 2 != 0) cout <<  - ;       }       m -= 2;     }   }
#include <bits/stdc++.h>   int q, n;   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d , &n);       int b = sqrt(2 * n + 4);       while ((b + 1) * (b + 2) / 2 > n) b--;       int a = n - (b + 1) * (b + 2) / 2;       printf( 133 );       for (int i = 1; i <= a; i++) printf( 7 );       for (int i = 1; i <= b; i++) printf( 3 );       printf( 7 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e;   int ar[200100];   int ar1[200100];   int main() {     vector<int> arr(200100);     string s, s1;     cin >> s;     cin >> s1;     a = min(s.length(), s1.length());     b = a;     c = 1;     while ((c <= a) && (s[s.length() - c] == s1[s1.length() - c])) ++c;     cout << (a - c + 1) + max(s.length(), s1.length()) - c + 1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long t[n + 1], c[n + 1];     for (int i = 1; i <= n; i++) {       cin >> t[i] >> c[i];       t[i]++;       if (t[i] > n) {         t[i] = n;       }     }     long long dp[n + 1][n + 1];     for (int i = 1; i < n + 1; i++) {       dp[0][i] = 100000000000000;     }     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = n; j >= 0; --j) {         dp[i][j] = dp[i - 1][j];         if (j >= t[i]) {           dp[i][j] = min(dp[i][j], dp[i - 1][j - t[i]] + c[i]);         }         if (j != n) {           dp[i][j] = min(dp[i][j], dp[i][j + 1]);         }       }     }     cout << dp[n][n];   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   const int mod = 998244353;   long long n, k, ans;   long long dp[N][N], dp2[N];   signed main() {     cin >> n >> k;     dp[0][0] = 1;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= i; j++) {         for (long long l = i - j; l <= i - 1; l++) {           dp[i][j] = (dp[i][j] + dp[l][min(l, j)]) % mod;         }       }     }     for (long long i = 1; i <= n; i++) {       dp2[i] = (dp[n][i] - dp[n][i - 1] + mod) % mod;     }     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         if (k > i * j) ans = (ans + (dp2[i] * dp2[j] % mod)) % mod;       }     }     cout << (ans * 2) % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   int n, f[200200][3];   vector<int> E[200200];   void dfs(int u) {     if (E[u].empty())       f[u][2] = 1;     else       f[u][0] = 1;     for (int v : E[u]) {       dfs(v);       f[u][2] = (1ll * f[u][2] * (f[v][0] + f[v][2]) +                  1ll * (f[u][1] + f[u][2]) * (f[v][1] + f[v][2])) %                 998244353;       f[u][1] = (1ll * f[u][1] * (f[v][0] + f[v][2]) +                  1ll * f[u][0] * (f[v][1] + f[v][2])) %                 998244353;       f[u][0] = 1ll * f[u][0] * (f[v][0] + f[v][2]) % 998244353;     }   }   int main() {     n = read();     for (int i = 2; i <= n; ++i) E[read()].push_back(i);     dfs(1);     printf( %d n , (f[1][0] + f[1][2]) % 998244353);     return 0;   }
#include <cstdio>   #include <iostream>   #include <cstring>   #include <algorithm>   #include <cmath>   #include <bitset>   #include <vector>   #include <unordered_map>   using namespace std;      const int N = 100007, M = 500007, INF = 0x3f3f3f3f;      typedef long long ll;   typedef int itn;      int n, m, t, x;   int fa[N];   int deep[N];   int maxx;   int num[N];//每一层结点个数   int cnt;   int lson[N];//叶子节点   int head[N], ver[M], edge[M], nex[M], tot;   bitset<N> f[2007];//能否凑齐 x，使用 bitset 优化   int val[N];   unordered_map<int, int> vis;   //int vis[N];   bool ok[N];   vector<int> v[N];      void add(int x, itn y)   {    ver[tot] = y;    nex[tot] = head[x];    head[x] = tot ++ ;   }      void dfs1(int x)   {    deep[x] = deep[fa[x]] + 1;//这里根结点 deep[1] = 1 所以不用再 +1 了    num[deep[x]] ++ ;    maxx = max(maxx, deep[x]);//树的直径，实际上也就是最大深度    if (head[x] == -1) //没有子节点，说明是叶子结点     lson[deep[x]] ++ ;//每层的叶子结点个数    for (int i = head[x]; ~i; i = nex[i]) {     int y = ver[i];     dfs1(y);    }   }      void dfs2(itn x, int t)   {    if(x == 0)     return;    for (int i = 0; i < (int)v[x].size(); ++ i) {     if(val[x] > t || f[x - 1][t])      break;     t -= val[x], ok[v[x][i]] = true;    }    dfs2(x - 1, t);   }      void init()   {       memset(head, -1, sizeof head);       tot = 0;   }      void solve()   {       init();    scanf( %d%d , &n, &x);    for (int i = 2; i <= n; ++ i) {     scanf( %d , &fa[i]);     //add(i, fa[i]);     add(fa[i], i);    }    dfs1(1);//预处理每层结点个数    //把抽象的树转化为一个个物品，存到 v 里，离散化一下，种类（结点个数）和个数（层数）    //cout <<  ok  << endl;    //一共cnt种，    for (int i = 1; i <= maxx; ++ i) {     if (vis[num[i]]) {              v[vis[num[i]]].push_back(i);     }     else {               vis[num[i]] = ++ cnt;               val[cnt] = num[i];               v[cnt].push_back(i);//来找最后选了第几层     }    }       f[0][0] = 1;          for (int i = 1; i <= cnt; ++ i) {           f[i] = f[i - 1];     itn Size = v[i].size();     for (int j = 1; j <= Size; j <<= 1) {      Size -= j;      f[i] |= (f[i] << (j * val[i]));     }     if(Size > 0)      f[i] |= f[i] << (Size * val[i]);    }       if(f[cnt][x]) {     printf( %d n , maxx);     dfs2(cnt, x);//还原dp的方案     for (int i = 1; i <= n; ++ i) {      putchar(ok[deep[i]] ?  a  :  b );     }    }    //凑不齐， a  有剩余    else {     int res = INF;     for (int i = x; i >= 0; -- i) {      if(f[cnt][i]) {       res = i;//找到能凑到的最大的数       break;      }     }     dfs2(cnt, res);     int pos = -1;     for (int i = 1; i <= maxx; ++ i)     {      if(!ok[i] && lson[i] >= x - res) {       pos = i;       break;      }     }        printf( %d n , maxx + 1);        for (int i = 1; i <= n; ++ i) {      if(deep[i] == pos && head[i] == -1) {       if(res == x) {        putchar( b );       }       else        putchar( a ), ++ res;      }      else {       putchar(ok[deep[i]] ?  a  :  b );      }     }    }    return ;   }      itn main()   {       solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5, inf = 1e9;   int a[maxn];   struct segtree {     int lb, rb;     int mn = 0;     segtree *l, *r;     segtree(int _lb, int _rb) {       lb = _lb, rb = _rb;       if (lb == rb)         mn = a[lb];       else {         int t = (lb + rb) / 2;         l = new segtree(lb, t);         r = new segtree(t + 1, rb);         mn = min(l->mn, r->mn);       }     }     int rmq(int lq, int rq) {       if (lb >= lq && rb <= rq)         return mn;       else if (lb > rq || rb < lq)         return inf;       return min(l->rmq(lq, rq), r->rmq(lq, rq));     }   };   segtree *p;   vector<pair<int, int> > ans;   void solve(int l, int r, int d) {     if (l > r) return;     int mn = p->rmq(l, r);     while (mn > d) ans.push_back({l + 1, r + 1}), d++;     int lb = l, rb = r;     while (lb != rb) {       int t = (lb + rb) / 2;       if (p->rmq(l, t) == d)         rb = t;       else         lb = t + 1;     }     solve(l, lb - 1, d);     solve(lb + 1, r, d);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     p = new segtree(0, n - 1);     solve(0, n - 1, 0);     cout << ans.size() <<   n ;     for (auto x : ans) cout << x.first <<     << x.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<string> v;     map<char, int> m;     int k;     cin >> k;     string q;     cin >> q;     int l = q.size();     int flag = 1;     int cnt = 0;     string s;     if (l < k) {       cout <<  NO ;       return 0;     } else {       cnt = 1;       s += q[0];       m[q[0]] = 1;       for (int i = 1; i < l; i++) {         if (m[q[i]] == 0 and cnt < k) {           m[q[i]] += 1;           cnt++;           v.push_back(s);           s =   ;           s += q[i];         } else {           s += q[i];         }       }       v.push_back(s);     }     if (v.size() == k) {       cout <<  YES  << endl;       for (int i = 0; i < v.size(); i++) cout << v[i] << endl;     } else {       cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 5000;   const long long MAX_Q = 10000;   struct Node {     vector<long long> val;     vector<int> nex;   };   long long cnt = 1, cur = 0,             pows[5] = {                 1LL, (MAX_Q + 1LL), (MAX_Q + 1LL) * (MAX_Q + 1LL),                 (MAX_Q + 1LL) * (MAX_Q + 1LL) * (MAX_Q + 1LL),                 (MAX_Q + 1LL) * (MAX_Q + 1LL) * (MAX_Q + 1LL) * (MAX_Q + 1LL)};   Node G[MAX_N];   void dfs(int pos, int dep, long long uplim) {     if (uplim > MAX_Q) {       cur += pows[dep] - 1LL;       return;     }     if (dep == 1) {       for (int i = 1; i <= uplim; i++) {         cur++;         G[pos].val.push_back(cur);         G[pos].nex.push_back(-1);       }       return;     }     long long cur_uplim = uplim;     for (int i = 1; i <= uplim + 1; i++) {       cnt++;       G[pos].nex.push_back(cnt);       dfs(cnt, dep - 1, cur_uplim);       if (i != uplim + 1) {         cur++;         G[pos].val.push_back(cur);         cur_uplim = cur + 1;       }     }   }   int main() {     dfs(1, 5, 1);     long long cx = 1, range_l = 1, range_r = cur;     for (int t = 4; t >= 0; t--) {       vector<long long> D;       if (cx != -1 && cx <= cnt && G[cx].val.size() >= 1) {         D = G[cx].val;       } else {         for (int i = 1; i <= MAX_Q; i++)           D.push_back((range_l - 1LL) + 1LL * i * pows[t]);       }       cout << D.size();       for (int i = 0; i < D.size(); i++) cout <<     << D[i];       cout << endl;       int S;       cin >> S;       if (S == -1) break;       if (cx != -1 && cx <= cnt && G[cx].val.size() >= 1)         cx = G[cx].nex[S];       else         cx = -1;       if (S >= 1) range_l = D[S - 1] + 1LL;       if (S < (int)D.size() - 1) range_r = D[S] - 1LL;     }     return 0;   }