malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > upd;   struct query {     int l, r, t, id, ans;     query() {}     query(int _l, int _r, int _t, int _id) {       l = _l;       r = _r;       t = _t;       id = _id;     }   };   vector<query> que;   stack<pair<int, int> > S;   vector<int> V;   int M[1005][105];   int sz[1005];   int cnt[300005];   int data[100005];   int B;   int l = 1, r = 0, t = 0, Ans = 1;   int cmp(query a, query b) {     if (a.l / B != b.l / B) return a.l < b.l;     if (a.r / B != b.r / B) return a.r < b.r;     return a.t < b.t;   }   int cmpid(query a, query b) { return a.id < b.id; }   int Upd() {     for (int i = (Ans / 100); i < (1000); i++)       if (sz[i] < 100) {         for (int j = (0); j < (100); j++)           if (!M[i][j]) {             return i * 100 + j;           }       }   }   void Add(int a) {     if (!M[a / 100][a % 100]) sz[a / 100]++;     M[a / 100][a % 100]++;     if (Ans == a) Ans = Upd();   }   void Del(int a) {     M[a / 100][a % 100]--;     if (!M[a / 100][a % 100]) {       sz[a / 100]--;       if (Ans > a) Ans = a;     }   }   void add(int a) {     Del(cnt[a]);     Add(++cnt[a]);   }   void del(int a) {     Del(cnt[a]);     Add(--cnt[a]);   }   int main() {     M[0][0] = 1e9;     int n, m;     scanf( %d%d , &n, &m);     B = pow(n, 2.0 / 3);     for (int i = (1); i < (n + 1); i++)       scanf( %d , &data[i]), V.push_back(data[i]);     while (m--) {       int co, a, b;       scanf( %d%d%d , &co, &a, &b);       if (co == 1)         que.push_back(query(a, b, (int)(upd).size(), (int)(que).size()));       else         upd.push_back(make_pair(a, b)), V.push_back(b);     }     sort(V.begin(), V.end());     V.erase(unique(V.begin(), V.end()), V.end());     for (int i = (1); i < (n + 1); i++)       data[i] = lower_bound(V.begin(), V.end(), data[i]) - V.begin() + 1;     for (int i = (0); i < ((int)(upd).size()); i++)       upd[i].second =           lower_bound(V.begin(), V.end(), upd[i].second) - V.begin() + 1;     sort(que.begin(), que.end(), cmp);     for (int i = (0); i < ((int)(que).size()); i++) {       while (l > que[i].l) {         l--;         add(data[l]);       }       while (r < que[i].r) {         r++;         add(data[r]);       }       while (r > que[i].r) {         del(data[r]);         r--;       }       while (l < que[i].l) {         del(data[l]);         l++;       }       while (t < que[i].t) {         int pos = upd[t].first;         S.push(make_pair(pos, data[pos]));         if (l <= pos && pos <= r) del(data[pos]);         data[pos] = upd[t].second;         if (l <= pos && pos <= r) add(data[pos]);         t++;       }       while (t > que[i].t) {         t--;         int pos = S.top().first;         if (l <= pos && pos <= r) del(data[pos]);         data[pos] = S.top().second;         if (l <= pos && pos <= r) add(data[pos]);         S.pop();       }       que[i].ans = Ans;     }     sort(que.begin(), que.end(), cmpid);     for (int i = (0); i < ((int)(que).size()); i++) printf( %d n , que[i].ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long N = 1e5 + 7;   long long p[N], cnt;   bool vis[N];   long long res1 = 0;   long long res2 = 0;   long long res3 = 0;   inline void init(long long NN) {     res1 = res2 = res3 = 0;     for (long long i = 2; i <= NN + res1 + res2 + res3; i++) {       res1 = res2 = res3 = 0;       if (vis[i]) continue;       p[++cnt] = i + res1 + res2 + res3;       res1 = res2 = res3 = 0;       for (long long j = 2; i * j <= NN; j++) vis[i * j] = true;       res1 = res2 = res3 = 0;     }   }   void solve() {     long long a, b;     cin >> a >> b;     res1 = res2 = res3 = 0;     long long now = b;     res1 = res2 = res3 = 0;     if (a % b)       printf( %lld n , a + res1 + res2 + res3);     else {       res1 = res2 = res3 = 0;       long long ans = 1;       res1 = res2 = res3 = 0;       for (long long j = 1; j <= cnt + res1 + res2 + res3; j++) {         res1 = res2 = res3 = 0;         if (b % p[j] == 0) {           res1 = res2 = res3 = 0;           long long tmp = a;           res1 = res2 = res3 = 0;           while (tmp % now == 0) tmp /= p[j];           res1 = res2 = res3 = 0;           ans = max(ans, tmp) + res1 + res2 + res3;           res1 = res2 = res3 = 0;           while (b % p[j] == 0) b /= p[j];           res1 = res2 = res3 = 0;         }       }       long long tmp = a;       if (b != 1) {         res1 = res2 = res3 = 0;         while (tmp % now == 0) tmp /= b;         res1 = res2 = res3 = 0;         ans = max(ans, tmp) + res1 + res2 + res3;         res1 = res2 = res3 = 0;       }       printf( %lld n , ans + res1 + res2 + res3);     }   }   signed main() {     long long t = 1;     res1 = res2 = res3 = 0;     init(100000);     cin >> t;     res1 = res2 = res3 = 0;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fib[100], A[100], B[100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n, najwieksza = 2;     fib[0] = 1;     fib[1] = 1;     for (; fib[najwieksza - 1] + fib[najwieksza - 2] <= 1e18; najwieksza++)       fib[najwieksza] = fib[najwieksza - 1] + fib[najwieksza - 2];     cin >> t;     while (t--) {       cin >> n;       vector<int> miejsca;       for (int i = najwieksza - 1; i > 0; i--)         if (fib[i] <= n) {           n -= fib[i];           miejsca.push_back(i);         }       miejsca.push_back(0);       reverse(miejsca.begin(), miejsca.end());       A[1] = 1;       B[1] = (miejsca[1] - 1) / 2;       for (int i = 2; i < (int)miejsca.size(); i++) {         A[i] = A[i - 1] + B[i - 1];         B[i] = A[i - 1] * ((miejsca[i] - miejsca[i - 1] - 1) / 2) +                B[i - 1] * ((miejsca[i] - miejsca[i - 1]) / 2);       }       cout << A[miejsca.size() - 1] + B[miejsca.size() - 1] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mediana(vector<int> &v) {     if (int(v.size()) % 2 == 1) return v[int(v.size()) / 2];     return v[int(v.size()) / 2 - 1];   }   bool esta(vector<int> &v, int x) {     for (int i = 0; i < int(v.size()); i++)       if (v[i] == x) return true;     return false;   }   int main() {     int n, x;     cin >> n >> x;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     int amount = 0;     while (mediana(v) != x) {       if (not esta(v, x))         v.push_back(x);       else if (mediana(v) < x)         v.push_back(1000000001);       else         v.push_back(-1);       amount++;       sort(v.begin(), v.end());     }     cout << amount << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e2 + 10;   const long long mod = 998244353;   const long long inf = (long long)4e17 + 5;   const int INF = 1e9 + 7;   const double pi = acos(-1.0);   long long inv(long long b) {     if (b == 1) return 1;     return (mod - mod / b) * inv(mod % b) % mod;   }   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n;   int ans[105];   int more[maxn], les[maxn];   int mmax, mmin;   int nex[maxn], pre[maxn];   inline void ask_m(int x) {     printf( ? );     fflush(stdout);     for (int i = 1; i <= n; i++) {       if (i == x)         printf(  2 );       else         printf(  1 );     }     puts(  );     fflush(stdout);     scanf( %d , more + x);     if (more[x] == 0) {       ans[x] = n;       mmax = x;     }   }   inline void ask_l(int x) {     printf( ? );     fflush(stdout);     for (int i = 1; i <= n; i++) {       if (i == x)         printf(  1 );       else         printf(  2 );     }     puts(  );     fflush(stdout);     scanf( %d , les + x);     if (les[x] == 0) {       ans[x] = 1;       mmin = x;     }   }   void solve() {     for (int i = 1; i <= n; i++) {       ask_m(i);     }     for (int i = 1; i <= n; i++) {       ask_l(i);     }     for (int i = 1; i <= n; i++) {       if (more[i] == i || !more[i]) continue;       nex[i] = more[i];       pre[more[i]] = i;     }     for (int i = 1; i <= n; i++) {       if (les[i] == i || !les[i]) continue;       nex[les[i]] = i;       pre[i] = les[i];     }     int fr;     for (int i = 1; i <= n; i++) {       if (!nex[i]) {         fr = i;         break;       }     }     for (int i = n; i >= 1; i--) {       ans[fr] = i;       fr = pre[fr];     }     printf( ! );     for (int i = 1; i <= n; i++) printf(  %d , ans[i]);     puts(  );     fflush(stdout);   }   int main() {     scanf( %d , &n);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   int n, ans;   int Dpos[N + 3];   char str[N + 10], Nstr[N + 10];   int main() {     scanf( %d%s , &n, str + 1);     int Ncnt = 0, Ned = n, Nmin = 0;     for (int i = 1; i <= n; i++) {       if (str[i] ==  ( )         Ncnt++;       else         Ncnt--;       if (Nmin > Ncnt) {         Nmin = Ncnt;         Ned = i;       }     }     if (Ncnt) printf( 0 n1 1 n ), exit(0);     int Npos = 1;     for (int i = Ned + 1; i <= n; i++) Dpos[Npos] = i, Nstr[Npos++] = str[i];     for (int i = 1; i <= Ned; i++) Dpos[Npos] = i, Nstr[Npos++] = str[i];     for (int i = 1, Icnt = 0; i <= n; i++) {       if (Nstr[i] ==  ( )         Icnt++;       else         Icnt--;       if (!Icnt) ans++;     }     int fans = ans;     int ansl = 1, ansr = 1;     for (int i = 1; i <= n;) {       int Pcnt = 0;       int j;       for (j = i; j <= n; j++) {         if (Nstr[j] ==  ( )           Pcnt++;         else           Pcnt--;         if (!Pcnt) break;       }       vector<pair<int, int> > vec;       Pcnt = 0;       int Ptot = 0;       for (int k = i + 1; k < j; k++) {         if (Nstr[k] ==  ( )           Pcnt++;         else           Pcnt--;         if (Pcnt == 0) {           if (vec.empty())             vec.push_back(make_pair(i + 1, k));           else             vec.push_back(make_pair(vec.back().second + 1, k));         }       }       for (auto it : vec) {         int L = it.first, R = it.second;         int Kcnt = 0, Ktot = 0;         for (int k = L + 1; k <= R - 1; k++) {           if (Nstr[k] ==  ( )             Kcnt++;           else             Kcnt--;           if (!Kcnt) Ktot++;         }         if (ans < fans - 1 + 2 + Ktot) {           ans = fans - 1 + 2 + Ktot;           ansl = L;           ansr = R;         }       }       Ptot = vec.size();       if (ans < Ptot + 1) {         ans = Ptot + 1;         ansl = i;         ansr = j;       }       i = j + 1;     }     ansl = Dpos[ansl];     ansr = Dpos[ansr];     if (ansl > ansr) swap(ansl, ansr);     printf( %d n%d %d n , ans, ansl, ansr);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[5005] = {0};   void ge(int a) {     if (a == 1)       printf( one n );     else if (a == 2)       printf( two n );     else if (a == 3)       printf( three n );     else if (a == 4)       printf( four n );     else if (a == 5)       printf( five n );     else if (a == 6)       printf( six n );     else if (a == 7)       printf( seven n );     else if (a == 8)       printf( eight n );     else if (a == 9)       printf( nine n );   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     if (n == 0)       printf( zero n );     else if (n == 1)       printf( one n );     else if (n == 2)       printf( two n );     else if (n == 3)       printf( three n );     else if (n == 4)       printf( four n );     else if (n == 5)       printf( five n );     else if (n == 6)       printf( six n );     else if (n == 7)       printf( seven n );     else if (n == 8)       printf( eight n );     else if (n == 9)       printf( nine n );     else if (n == 10)       printf( ten n );     else if (n == 11)       printf( eleven n );     else if (n == 12)       printf( twelve n );     else if (n == 13)       printf( thirteen n );     else if (n == 14)       printf( fourteen n );     else if (n == 15)       printf( fifteen n );     else if (n == 16)       printf( sixteen n );     else if (n == 17)       printf( seventeen n );     else if (n == 18)       printf( eighteen n );     else if (n == 19)       printf( nineteen n );     else if (n == 20)       printf( twenty n );     else if (n > 20 && n <= 29) {       printf( twenty- );       int k = n % 10;       ge(k);     } else if (n == 30) {       printf( thirty n );     } else if (n > 30 && n <= 39) {       printf( thirty- );       int k = n % 10;       ge(k);     } else if (n == 40)       printf( forty n );     else if (n > 40 && n <= 49) {       printf( forty- );       int k = n % 10;       ge(k);     } else if (n == 50)       printf( fifty n );     else if (n > 50 && n <= 59) {       printf( fifty- );       int k = n % 10;       ge(k);     } else if (n == 60)       printf( sixty n );     else if (n > 60 && n <= 69) {       printf( sixty- );       int k = n % 10;       ge(k);     } else if (n == 70)       printf( seventy n );     else if (n > 70 && n <= 79) {       printf( seventy- );       int k = n % 10;       ge(k);     } else if (n == 80)       printf( eighty n );     else if (n > 80 && n <= 89) {       printf( eighty- );       int k = n % 10;       ge(k);     } else if (n == 90)       printf( ninety n );     else if (n > 90 && n <= 99) {       printf( ninety- );       int k = n % 10;       ge(k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y, alpha;     int num;   };   int n, c[1510] = {}, ans[1510] = {};   vector<int> a[1510];   point p[1510];   int rec(int v, int pr) {     int r = 0;     for (int i = 0; i < a[v].size(); i++)       if (a[v][i] != pr) r += rec(a[v][i], v);     return (c[v] = r) + 1;   }   bool comp(point p1, point p2) { return (p1.alpha < p2.alpha); }   int rec2(int v, int t, int pr) {     int s = t;     for (int i = t + 1; i <= t + c[v]; i++)       if (p[i].x < p[s].x || (p[i].x == p[s].x && p[i].y < p[s].y)) s = i;     swap(p[s], p[t]);     for (int i = t + 1; i <= t + c[v]; i++)       if (p[i].x != p[t].x)         p[i].alpha = atan((p[i].y - p[t].y) / (p[i].x - p[t].x));       else if (p[i].y > p[t].y)         p[i].alpha = 3.1415926536 / 2;       else         p[i].alpha = -3.1415926536 / 2;     sort(p + t + 1, p + t + c[v] + 1, comp);     ans[p[t++].num] = v;     for (int i = 0; i < a[v].size(); i++)       if (a[v][i] != pr) t += rec2(a[v][i], t, v);     return c[v] + 1;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       a[u].push_back(v);       a[v].push_back(u);     }     for (int i = 0; i < n; i++) {       cin >> p[i].x >> p[i].y;       p[i].num = i;     }     rec(0, -1);     rec2(0, 0, -1);     for (int i = 0; i < n; i++) cout << ans[i] + 1 <<    ;   }
#include <bits/stdc++.h>   const int maxn = (int)1e6;   const int mod = (int)1e9 + 7;   using namespace std;   int n;   long long dp[maxn];   long long a[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     dp[0] = abs(a[0]);     for (int i = 1; i < n; i++) {       dp[i] = abs(a[i] - a[i - 1]) + dp[i - 1];     }     cout << dp[n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool mycomp(vector<long long int> a, vector<long long int> b) {     long long int acost = min(2 * a[0], a[1]) - min(a[0], a[1]);     long long int bcost = min(2 * b[0], b[1]) - min(b[0], b[1]);     return acost > bcost;   }   long long int fn(vector<vector<long long int> > arr, long long int n,                    long long int f) {     sort(arr.begin(), arr.end(), mycomp);     long long int productSold = 0;     for (long long int i = 0; i < f; i++) {       productSold += min(2 * arr[i][0], arr[i][1]);     }     for (long long int i = f; i < n; i++) {       productSold += min(arr[i][0], arr[i][1]);     }     return productSold;   }   int32_t main() {     long long int n, f;     cin >> n >> f;     vector<vector<long long int> > arr(n);     for (long long int i = 0; i < n; i++) {       long long int k, l;       cin >> k >> l;       arr[i].push_back(k);       arr[i].push_back(l);     }     long long int ans = fn(arr, n, f);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long f(int x, int len) {     if (len == 0) return 0;     if (x > len)       return (long long)len * (2 * x - len - 1) / 2;     else       return (long long)x * (x - 1) / 2 + len - x + 1;   }   bool ok(int x) {     if (f(x, k - 1) + f(x, n - k) + x <= m)       return 1;     else       return 0;   }   int main() {     cin >> n >> m >> k;     int l = 1, r = 1e9;     while (r - l > 1) {       int mid = (l + r) / 2;       if (ok(mid)) {         l = mid;       } else {         r = mid;       }     }     int res = 0;     if (ok(l)) res = l;     if (ok(r)) res = r;     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int arr[310], nex[310], T, N;   bool can, isRoot[310];   void dfs(int x, int val) {     if (T < 0) return;     arr[x] += val;     if (nex[x] != -1) {       T -= arr[x];       dfs(nex[x], arr[x]);     }   }   long long int memo[310][100000 + 100];   long long int solve(int pos, int val) {     if (pos == 0) return val == 0;     if (val <= 0) return val == 0;     if (memo[pos][val] != -1) return memo[pos][val];     long long int ret = solve(pos - 1, val);     if (val - arr[pos] >= 0)       ret = (ret + solve(pos, val - arr[pos])) % 1000000007;     return memo[pos][val] = ret;   }   long long int t[100000 + 100];   int main() {     int Q, x, y;     while (cin >> N >> Q >> T) {       for (int i = 1; i <= N; i++) scanf( %d , &arr[i]);       memset(nex, -1, sizeof nex);       memset(isRoot, true, sizeof isRoot);       for (int i = 0; i < Q; i++) {         scanf( %d %d , &x, &y);         nex[x] = y;         isRoot[y] = false;       }       bool in = false;       for (int i = 1; i <= N; i++)         if (isRoot[i] && nex[i] != -1) {           in = true;           dfs(i, 0);         }       if ((Q > 0 && in == false) || T < 0) {         cout << 0 << endl;         return 0;       }       memset(memo, -1, sizeof memo);       t[0] = 1;       for (int i = 1; i <= N; i++)         for (int j = 0; j <= T; j++) {           if (j - arr[i] >= 0) t[j] = (t[j] + t[j - arr[i]]) % 1000000007;         }       cout << t[T] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 150, M = 150, OO = 0x3f3f3f3f;   int n, arr[2005], temp, ans;   void DFS(int u) {     temp++;     if (arr[u] == -1) return;     DFS(arr[u]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , arr + i);     }     for (int i = 1; i <= n; ++i) {       temp = 0;       DFS(i);       ans = max(ans, temp);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int convert(int k) {     if (k < 2)       return k;     else if (k < 5)       return k - 1;     else       return k - 2;   }   int main() {     string s[6];     int A[6][6] = {3, 3, 4, 4, 3, 3, 3, 3, 4, 4, 3, 3, 2, 2, 3, 3, 2, 2,                    2, 2, 3, 3, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1};     for (int i = 0; i < 6; i++) {       cin >> s[i];     }     int best = 0, besti = 0, bestj = 0;     for (int i = 0; i < 6; i++) {       for (int j = 0; j < 8; j++) {         if (s[i][j] ==  . ) {           if (A[i][convert(j)] > best) {             best = A[i][convert(j)];             besti = i;             bestj = j;           }         }       }     }     s[besti][bestj] =  P ;     for (int i = 0; i < 6; i++) {       cout << s[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (a < b) a = b;   }   const int oo = 1 << 30;   const double eps = 1e-7;   const int N = 1 << 10;   const int M = 1;   const long long P = 1000000007;   long long dp[N][N];   int mx;   char s[N];   inline int is(int k) { return 4 == k || 7 == k; }   inline int to(int f, int flag) {     flag = is(flag);     if (0 == f) return 0;     if (1 == f || mx + 1 == f) return flag ? f - 1 : (mx + 1);     return flag ? 0 : f - 1;   }   long long dfs(int id, int f) {     if (id < 0) return !f;     long long &r = dp[id][f];     if (-1 != r) return r;     r = 0;     id--;     r += 8 * dfs(id, to(f, 0));     r += 2 * dfs(id, to(f, 4));     return r %= P;   }   void pre() {     (memset((dp), -1, sizeof(dp)));     dfs(1001, mx + 1);   }   long long dfs_d(int id, int f) {     if (id < 0) return !f;     int k, u;     long long r = 0;     u = s[id];     id--;     for (k = 0; k < (u); k++) r += dfs(id, to(f, k));     r += dfs_d(id, to(f, k));     return r %= P;   }   long long doit(int flag) {     (memset((s), 0, sizeof(s)));     scanf( %s , s);     int i, sn;     sn = strlen(s);     for (i = 0; i < (sn); i++) s[i] -=  0 ;     reverse(s, s + sn);     s[0] -= flag;     for (i = 0; s[i] < 0; i++) {       s[i] = 9;       s[i + 1]--;     }     return dfs_d(sn, mx + 1);   }   int main() {     int T, _ = 0;     long long ans = 0;     scanf( %d %d , &T, &mx);     pre();     while (_++ < T) {       ans = -doit(1);       ans += doit(0);       ans = (ans % P + P) % P;       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     int b;     int c;     int d;     int e;     cin >> a;     int aa[a];     for (b = 0; b < a; ++b) {       cin >> aa[b];     }     d = aa[0];     c = 0;     b = 0;     vector<int> ab;     while (b < a) {       if (aa[b] > d) d = aa[b];       if ((b + 1) == d) c = c + 1;       b = b + 1;     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q, a[100100], head, tail;   long long n;   long long solve(long long n, long long k) {     if (k & 1) return (k + 1) / 2;     if (n & 1)       if (k == 2)         return solve(n / 2, n / 2) + (n + 1) / 2;       else         return solve(n / 2, k / 2 - 1) + (n + 1) / 2;     else       return solve(n / 2, k / 2) + n / 2;   }   int main() {     scanf( %I64d , &n);     for (scanf( %d , &q); q--;) {       long long x;       scanf( %I64d , &x);       printf( %I64d n , solve(n, x));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, k;   vector<long long int> v[100005];   vector<long long int> res;   long long int ares[100005];   long long int was[100005];   int dfs(long long int ind, long long int c) {     if (c > 100005) {       return -1;     }     if (ares[ind]) return 1;     if (!v[ind].size()) {       ares[ind] = 1;       res.push_back(ind);       return 1;     }     for (auto i : v[ind]) {       int r = dfs(i, c + 1);       if (r < 0) {         return -1;       }     }     ares[ind] = 1;     res.push_back(ind);     return 1;   }   int main() {     cin >> n >> k;     long long int *arr = new long long int[k];     for (long long int i = 0; i < k; i++) {       cin >> arr[i];       arr[i]--;     }     for (long long int i = 0; i < n; i++) {       ares[i] = 0;       long long int a, b;       cin >> b;       for (long long int j = 0; j < b; j++) {         cin >> a;         a--;         v[i].push_back(a);       }     }     for (long long int i = 0; i < k; i++) {       int r = dfs(arr[i], 0);       if (r < 0) {         cout << -1;         return 0;       }     }     cout << res.size() << endl;     for (auto i : res) {       cout << (i + 1) <<    ;     }     return 0;   }