malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long pow(long long x, long long v) {     if (v == 0) return 1LL;     if (v % 2) return (x % MOD) * pow(x % MOD, v - 1) % MOD;     return pow((x * x) % MOD, v / 2) % MOD;   }   int main() {     int n;     long long x, sum = 0, v, mx = 0;     scanf( %d%lld , &n, &x);     map<long long, int> cnt;     vector<long long> a(n);     for (int i = 0; i < n; ++i)       scanf( %lld , &a[i]), sum += a[i], mx = max(mx, a[i]);     for (int i = 0; i < n; ++i) cnt[sum - a[i]]++;     for (map<long long, int>::iterator it = cnt.begin(); it != cnt.end(); ++it) {       v = it->first;       if (it->second % x == 0) {         cnt[v + 1] += it->second / x;       } else         break;     }     v = min(v, sum);     printf( %lld , pow(x, v));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       vector<int> numbers(n);       vector<int> trayectoria(n + 1);       for (int &i : numbers) cin >> i;       if (numbers[0] == 1) {         cout << n + 1 <<    ;         for (int i = 1; i < n + 1; i++) cout << i <<    ;         cout <<   n ;       } else if (numbers[n - 1] == 0) {         for (int i = 1; i < n; i++) cout << i <<    ;         cout << n <<     << n + 1 <<    ;         cout <<   n ;       } else {         bool poss = false;         for (int i = 0; i < n; i++) {           if (i < n - 1 && numbers[i] < numbers[i + 1]) {             for (int j = 0; j < i; j++) cout << j + 1 <<    ;             cout << i + 1 <<     << n + 1 <<    ;             for (int j = i + 1; j < n; j++) cout << j + 1 <<    ;             cout << endl;             poss = true;             break;           }         }         if (!poss) cout <<  -1 n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (cin >> a >> b) {       if (a == 0 && b == 0)         cout <<  NO  << endl;       else {         c = abs(a - b);         if (c == 0 || c == 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, m, k, t, mx, mi, x, y, dx, dy, idx, cnt, tot, sum, res, flag, st;   vector<int> e[maxn];   void dfs(int u, int pre, int dep, int op) {     if (dep > mx) {       mx = dep;       idx = u;     }     if (u == y && op) {       if (dep <= dx) {         flag = 1;         return;       }     }     for (int v : e[u]) {       if (v == pre) continue;       dfs(v, u, dep + 1, op);     }   }   int main() {     scanf( %d , &t);     while (t--) {       flag = 0;       scanf( %d %d %d %d %d , &n, &x, &y, &dx, &dy);       for (int i = 1; i <= n; i++) {         e[i].clear();       }       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d %d , &u, &v);         e[u].push_back(v);         e[v].push_back(u);       }       mx = 0;       dfs(x, 0, 0, 1);       if (flag) {         puts( Alice );         continue;       }       mx = 0;       dfs(idx, 0, 0, 0);       if (2 * dx >= mx || dy <= 2 * dx) {         puts( Alice );       } else {         puts( Bob );       }     }     return 0;   }
#include <bits/stdc++.h>   int n;   int length;   int num[1000];   int main() {     scanf( %d , &n);     while (n--) {       int max = 0;       int mark = 0;       scanf( %d , &length);       for (int i = 1; i <= length; i++) {         scanf( %d , &num[i]);         if (num[i] > (i + mark)) {           mark += num[i] - i - mark;         }       }       printf( %d n , mark);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<pair<int, pair<int, int> > > ans;     int v[4][n];     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < n; ++j) {         cin >> v[i][j];       }     }     for (int i = 1; i < 3; i++) {       for (int j = 0; j < n; j++) {         if (v[i][j] > 0) {           int x = 0;           if (i == 2) x = 3;           if (v[x][j] == v[i][j]) {             ans.push_back({v[i][j], {x + 1, j + 1}});             v[i][j] = 0;           }         }       }     }     int koln = 0;     for (int i = 1; i < 3; i++) {       for (int j = 0; j < n; j++) {         if (v[i][j] > 0) koln++;       }     }     if (koln == 2 * n) {       cout << -1;       return 0;     }     int fl = 0;     while (fl < koln) {       for (int i = 1; i < 3; ++i) {         for (int j = 0; j < n; ++j) {           if (v[i][j] > 0) {             if (i == 1) {               if (j < n - 1) {                 if (v[i][j + 1] == 0) {                   swap(v[i][j], v[i][j + 1]);                   ans.push_back({v[i][j + 1], {i + 1, j + 2}});                 }                 if (v[0][j + 1] == v[i][j + 1]) {                   ans.push_back({v[i][j + 1], {1, j + 2}});                   v[i][j + 1] = 0;                   fl++;                 }               } else if (v[2][j] == 0) {                 ans.push_back({v[i][j], {3, j + 1}});                 swap(v[i][j], v[2][j]);                 if (v[2][j] == v[3][j]) {                   ans.push_back({v[2][j], {4, j + 1}});                   v[2][j] = 0;                   fl++;                 }               }             } else {               if (j > 0) {                 if (v[i][j - 1] == 0) {                   swap(v[i][j], v[i][j - 1]);                   ans.push_back({v[i][j - 1], {i + 1, j}});                 }                 if (v[3][j - 1] == v[i][j - 1]) {                   ans.push_back({v[i][j - 1], {4, j}});                   v[i][j - 1] = 0;                   fl++;                 }               } else {                 if (v[1][j] == 0) {                   ans.push_back({v[i][j], {2, j + 1}});                   swap(v[1][j], v[i][j]);                 }                 if (v[1][j] == v[0][j]) {                   ans.push_back({v[1][j], {1, j + 1}});                   v[1][j] = 0;                   fl++;                 }               }             }           }         }       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].first <<     << ans[i].second.first <<                << ans[i].second.second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   template <typename F>   inline void write(F x, char ed =   n ) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar( 0  | st[tp--]);     putchar(ed);   }   template <typename T>   inline void write(T *st, int n, string s =   ) {     if (s.size()) cout << s <<  :  ;     while (n--) write(*st++,    );     puts(  );   }   const int N = 200050;   const int P = 1e9 + 7;   long long len[N], p[N], sum[N], ans;   int L[N], R[N], n;   long long fpw(long long x, long long mi, long long res = 1) {     for (; mi; mi >>= 1, x = x * x % P)       if (mi & 1) res = res * x % P;     return res;   }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(L[i]);     for (int i = 1; i <= n; ++i) read(R[i]), len[i] = R[i] - L[i] + 1;     long long ans = p[0] = 1;     len[0] = 1;     sum[0] = 1;     for (int i = 1; i < n; ++i) {       p[i] = max(0, min(R[i], R[i + 1]) - max(L[i], L[i + 1]) + 1);       p[i] = p[i] * fpw(len[i] * len[i + 1] % P, P - 2) % P,       p[i] = (P + 1 - p[i]) % P;       ans = (ans + p[i] + (i > 1 ? 2 * p[i] * sum[i - 2] : 0)) % P,       sum[i] = (sum[i - 1] + p[i]) % P;       int tr = min(min(R[i], R[i + 1]), R[i - 1]),           tl = max(max(L[i], L[i + 1]), L[i - 1]);       int t = max(tr - tl + 1, 0) *               fpw(len[i - 1] * len[i] % P * len[i + 1] % P, P - 2) % P;       t = (1ll - (1 - p[i - 1] + 1 - p[i]) + t) % P;       ans = (ans + 2 * t) % P;     }     write((ans % P + P) % P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s.size() == 1 &&         (s[0] ==  A  || s[0] ==  I  || s[0] ==  M  || s[0] ==  O  ||          s[0] ==  T  || s[0] ==  U  || s[0] ==  V  || s[0] ==  W  ||          s[0] ==  X  || s[0] ==  Y  || s[0] ==  H )) {       cout <<  YES ;       return 0;     }     for (int i = 0; i < s.size() / 2; i++)       if (s[i] == s[s.size() - 1 - i] &&           (s[i] ==  A  || s[i] ==  I  || s[i] ==  M  || s[i] ==  O  ||            s[i] ==  T  || s[i] ==  U  || s[i] ==  V  || s[i] ==  W  ||            s[i] ==  X  || s[i] ==  Y  || s[i] ==  H ))         continue;       else {         cout <<  NO ;         return 0;       }     if (s.size() % 2 == 1) {       if (s[s.size() / 2] ==  B ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  C ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  D ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  E ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  F ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  G ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  J ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  K ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  L ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  P ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  N ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  Q ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  R ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  S ) {         cout <<  NO ;         return 0;       }       if (s[s.size() / 2] ==  Z ) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 500002;   const long long mod = 1000000000;   const long double eps = 1e-9;   const long long inf = ((1ll << 31ll) - 1ll);   const long long INF = 2000000000000000000ll;   const long double pi = acos(-1);   long long qpow(long long b, long long e) {     if (!e) return 1;     if (e & 1) return qpow(b, e - 1) * b;     long long pwur = qpow(b, e >> 1);     return pwur * pwur;   }   long long modinv(long long x) { return qpow(x, mod - 2); }   long long n, a[maxn], lst, psum[maxn], ssum[maxn];   bool try_(long long id) {     long long sw = 0;     for (long long i = id; i <= n; i++) {       if (psum[i] <= psum[i - id]) return false;     }     return true;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(0);     srand(time(NULL));     cin >> n;     for (long long i = 1; i <= (n + 1) / 2; i++) {       cin >> a[i];     }     cin >> lst;     for (long long i = (n + 1) / 2 + 1; i <= n; i++) {       a[i] = lst;     }     for (long long i = 1; i <= n; i++) psum[i] = psum[i - 1] + a[i];     for (long long i = n; i >= 1; i--) ssum[i] = ssum[i + 1] + a[i];     if (lst >= 0) {       if (try_(n))         cout << n <<   n ;       else         cout << -1 <<   n ;       return 0;     }     long long cnt = 0;     for (long long i = 1; i <= n; i++) {       if ((psum[i] > 0 && ssum[n - i + 1] > 0) && (i >= (n + 1) / 2)) {         if (try_(i)) {           cout << i <<   n ;           return 0;         } else {           cnt++;         }       }     }     cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register char ch;     while (!isdigit(ch = getchar()))       ;     register long long x = ch ^  0 ;     while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^  0 );     return x;   }   vector<pair<long long, long long> > e[200005];   long long n, m, q, a[200005], b[200005], c[200005], sum[200005 << 2],       lzy[200005 << 2];   void build(long long o, long long l, long long r, long long p[]) {     lzy[o] = 0;     if (l == r) {       sum[o] = p[l];       return;     }     long long mid = l + r >> 1;     build(o << 1, l, mid, p);     build(o << 1 | 1, mid + 1, r, p);     sum[o] = min(sum[o << 1], sum[o << 1 | 1]);   }   void pushdown(long long o) {     sum[o << 1] += lzy[o];     sum[o << 1 | 1] += lzy[o];     lzy[o << 1] += lzy[o];     lzy[o << 1 | 1] += lzy[o];     lzy[o] = 0;   }   void updata(long long o, long long l, long long r, long long L, long long R,               long long val) {     if (L == l && r == R) {       sum[o] += val;       lzy[o] += val;       return;     }     if (lzy[o]) pushdown(o);     long long mid = l + r >> 1;     if (L <= mid) updata(o << 1, l, mid, L, min(mid, R), val);     if (R > mid) updata(o << 1 | 1, mid + 1, r, max(mid + 1, L), R, val);     sum[o] = min(sum[o << 1], sum[o << 1 | 1]);   }   signed main() {     n = read();     m = read();     q = read();     for (long long i = 1; i < n; ++i) {       a[i] = read();       b[i + 1] = read();     }     build(1, 1, n, b);     for (long long i = 1; i <= m; ++i) {       long long u, v, w;       u = read();       v = read();       w = read();       e[u].push_back(make_pair(v, w));     }     for (long long i = 1; i <= n; ++i) {       for (long long j = 0; j < e[i].size(); ++j) {         long long v = e[i][j].first, w = e[i][j].second;         updata(1, 1, n, 1, v, w);       }       c[i] = sum[1] + a[i];     }     build(1, 1, n, c);     printf( %lld n , sum[1]);     while (q--) {       long long x, y;       x = read();       y = read();       updata(1, 1, n, x, x, y - a[x]);       a[x] = y;       printf( %lld n , sum[1]);     }     return 0;   }
#include <bits/stdc++.h>   const int t = 50;   int f[t][t][t], g[t][t];   long long p[t];   int cnt;   void mul(int c[t][t], int a[t][t], int b[t][t], int n) {     int d[t][t];     memset(d, 0, sizeof d);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) d[i][k] ^= a[i][j] & b[j][k];     memcpy(c, d, sizeof d);   }   bool quick(long long m, int n) {     int i, j, k, res[t], ans[t];     for (i = 0; i < n; i++) ans[i] = 1;     for (i = 0; m; m >>= 1, i++)       if (m & 1) {         memset(res, 0, sizeof res);         for (j = 0; j < n; j++)           for (k = 0; k < n; k++) res[k] ^= ans[j] & f[i][j][k];         memcpy(ans, res, sizeof ans);       }     for (i = 0; i < n && ans[i]; i++)       ;     return i == n;   }   bool checker(long long m, int n) {     if (!quick(m, n)) return false;     for (int i = 0; i < cnt; i++)       if (quick(p[i], n)) return false;     return true;   }   int main() {     int ans, i, j, n;     long long s, m;     srand(0x51ac);     scanf( %d , &n);     m = s = (1ll << n) - 1;     for (cnt = 0, i = 2; i * (long long)i <= s; i++)       if (s % i == 0) {         p[cnt++] = m / i;         for (; s % i == 0; s /= i)           ;       }     if (s != 1) p[cnt++] = m / s;     do {       memset(f, 0, sizeof f);       for (i = 1; i < n; i++) f[0][i][i - 1] = 1;       for (f[0][0][n - 1] = i = 1; i < n; i++, j >>= 1)         f[0][i][n - 1] = rand() & 1;       for (i = 1; i < n; i++) mul(f[i], f[i - 1], f[i - 1], n);     } while (!checker(m, n));     for (i = 0; i < n; i++) printf( %d  , f[0][n - 1 - i][n - 1]);     for (puts(  ), i = 0; i < n; i++) printf( 1  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   int n;   int main() {     scanf( %d , &n);     if (n <= 8) {       int a = 2;       int b = (n) / a;       int c = (n) % a;       for (int i = 1; i <= n;) {         if (c > 0) {           printf( %d  , c);           c--;           i++;         } else if (c == 0) {           for (int j = a - 1; j >= 0; j--) {             printf( %d  , i + j);           }           i += a;         }       }     } else {       int a;       for (a = 3; a <= 1000; a++) {         if (a * a > n) break;       }       a--;       int b = (n) / a;       int c = n % a;       for (int i = 1; i <= n;) {         if (c > 0) {           printf( %d  , c);           c--;           i++;         } else if (c == 0) {           for (int j = a - 1; j >= 0; j--) {             printf( %d  , i + j);           }           i += a;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n;   int mxm[4 * maxn];   int get(int id, int L, int R, int l, int r, int x) {     if (l >= r) return -1;     if (L == l and R == r) {       if (mxm[id] < x) return -1;       if (L + 1 == R) return L;       int mid = (L + R) >> 1;       if (mxm[2 * id + 0] >= x) return get(2 * id + 0, L, mid, L, mid, x);       return get(2 * id + 1, mid, R, mid, R, x);     }     int mid = (L + R) >> 1;     int k = get(2 * id + 0, L, mid, l, min(mid, r), x);     if (k != -1) return k;     return get(2 * id + 1, mid, R, max(l, mid), r, x);   }   void change(int id, int L, int R, int idx, int x) {     if (L + 1 == R) {       mxm[id] = x;       return;     }     int mid = (L + R) >> 1;     if (idx < mid)       change(2 * id + 0, L, mid, idx, x);     else       change(2 * id + 1, mid, R, idx, x);     mxm[id] = max(mxm[2 * id + 0], mxm[2 * id + 1]);   }   long long fen[maxn];   void add(int x, int val) {     for (; x <= n; x += x & -x) fen[x] += val;   }   long long get(int x) {     long long ret = 0;     for (; x; x -= x & -x) ret += fen[x];     return ret;   }   long long get(int L, int R) { return get(R) - get(L - 1); }   int a[maxn];   int solve() {     int now = 1;     while (now < n) {       long long x = get(1, now - 1);       if (a[now] == x) return now;       x += a[now];       if (x > int(1e9)) return -1;       now = get(1, 1, n + 1, now + 1, n + 1, x);       if (now == -1) return now;     }     if (get(1, n - 1) == a[n]) return n;     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     int q;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> a[i];       add(i, a[i]);       change(1, 1, n + 1, i, a[i]);     }     for (int i = 1; i <= q; i++) {       int idx, x;       cin >> idx >> x;       add(idx, x - a[idx]);       a[idx] = x;       change(1, 1, n + 1, idx, a[idx]);       cout << solve() <<   n ;     }   }
#include <bits/stdc++.h>   char ch;   bool fs;   void re(int& x) {     while (ch = getchar(), ch < 33)       ;     if (ch ==  - )       fs = 1, x = 0;     else       fs = 0, x = ch - 48;     while (ch = getchar(), ch > 33) x = x * 10 + ch - 48;     if (fs) x = -x;   }   using namespace std;   pair<int, int> d[62];   int n;   int m, a[32], use[32][64][2048];   bool f[32][64][2048], edge[64][64];   int main() {     re(m);     for (int i = 1; i <= m; ++i) re(a[i]);     sort(a + 1, a + m + 1);     f[0][0][0] = 1;     for (int i = 1; i <= m; ++i)       for (int j = i; j <= 61; ++j)         for (int k = j * (j - 1) / 2; k <= 2000; ++k)           for (int l = 1; l <= j && l * a[i] <= k; ++l)             if (f[i - 1][j - l][k - l * a[i]]) {               f[i][j][k] = 1;               use[i][j][k] = l;               break;             }     for (int i = 1; i <= 61; ++i)       if (f[m][i][i * (i - 1) / 2]) {         printf( %d n , i);         int a = m, b = i, c = i * (i - 1) / 2;         while (a) {           int t = use[a][b][c];           for (int j = 1; j <= t; ++j) d[++n].first = ::a[a], d[n].second = n;           c -= t * ::a[a];           b -= t;           --a;         }         for (int j = 1; j <= n; ++j) {           sort(d + j, d + n + 1);           for (int k = j + 1; k <= j + d[j].first; ++k)             edge[d[j].second][d[k].second] = 1;           for (int k = j + d[j].first + 1; k <= n; ++k)             edge[d[k].second][d[j].second] = 1, --d[k].first;           d[j].first = 0;         }         for (int j = 1; j <= n; ++j, puts(  ))           for (int k = 1; k <= n; ++k) printf( %d , edge[j][k]);         return 0;       }     puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 + 7;   int n, k;   string second;   string s2;   string s1;   int main() {     cin >> n >> k;     cin >> second;     sort(second.begin(), second.end());     for (int i = 0; i < n; i++) {       if (second[i] != second[i + 1]) {         s2 += second[i];       }     }     second =   ;     second += s2;     sort(second.begin(), second.end());     for (int i = 0; i < second.size(); i++) {       s1 += second[i];       if (second[i] + 1 == second[i + 1] || second[i] == second[i + 1]) {         i++;       }     }     if (s1.size() >= k) {       int cnt = 0;       for (int i = 0; i < k; i++) {         cnt += s1[i] -  a  + 1;       }       cout << cnt;     } else {       cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 207;   int n, f[MAXN];   long long mmc_atual = 1;   vector<int> folhas, Gr[MAXN];   bool in_cycle[MAXN], mrk[MAXN];   int marca_ciclo(int u) {     if (in_cycle[u]) return 0;     in_cycle[u] = true;     return 1 + marca_ciclo(f[u]);   }   void dfsr(int u) {     mrk[u] = true;     bool flag = true;     for (int i = 0; i < (int)Gr[u].size(); i++) {       int viz = Gr[u][i];       flag = false;       if (mrk[viz]) continue;       dfsr(viz);     }     if (flag) folhas.push_back(u);   }   int dfs(int u) {     if (in_cycle[u]) return 0;     return 1 + dfs(f[u]);   }   long long mdc(long long a, long long b) { return (a == 0) ? b : mdc(b % a, a); }   long long mmc(long long a, long long b) { return (a / mdc(a, b)) * b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> f[i];       Gr[f[i]].push_back(i);     }     long long ans = 1;     long long mx_chain = 0;     for (int i = 1; i <= n; i++) {       if (!mrk[i]) {         int turtoise = i;         int hare = i;         do {           turtoise = f[turtoise];           hare = f[f[hare]];         } while (turtoise != hare);         int tam_ciclo = marca_ciclo(hare);         mmc_atual = mmc(mmc_atual, (long long)tam_ciclo);         dfsr(hare);       }     }     for (int i = 0; i < (int)folhas.size(); i++) {       int tam_chain = dfs(folhas[i]);       mx_chain = max(mx_chain, (long long)tam_chain);     }     if (mx_chain % mmc_atual != 0)       mx_chain = (mx_chain - mx_chain % mmc_atual) + mmc_atual;     ans = max(mmc_atual, mx_chain);     cout << ans << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using db = long double;   using ii = pair<int, int>;   const int N = 1e5 + 5, LG = 17, MOD = 998244353;   const int SQ = 225;   const long double EPS = 1e-7;   int n, m, a[N], b[N];   set<int> pos[N];   bool vis[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i < n + 1; i++) cin >> a[i];     cin >> m;     for (int i = 1; i < m + 1; i++) cin >> b[i];     sort(b + 1, b + m + 1);     vector<int> lis;     for (int i = 1; i < n + 1; i++) {       if (a[i] == -1) {         int p = lower_bound(lis.begin(), lis.end(), b[m]) - lis.begin();         if (p == lis.size()) lis.push_back(INT_MAX);         for (int j = m; j; --j) {           while (p > 0 && b[j] <= lis[p - 1]) --p;           lis[p] = min(lis[p], b[j]);         }       } else {         int p = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin();         if (p == lis.size()) lis.push_back(0);         lis[p] = a[i];         pos[p].insert(i);       }     }     int idx = n, prv = INT_MAX, ptr = m;     for (int i = lis.size() - 1; i >= 0; --i) {       auto it = pos[i].upper_bound(idx);       if (it != pos[i].begin()) {         --it;         if (a[*it] < prv) {           idx = *it;           prv = a[idx];           continue;         }       }       while (~a[idx]) --idx;       while (b[ptr] >= prv) --ptr;       prv = a[idx] = b[ptr];       vis[ptr] = true;     }     int tmp = 1;     for (int i = 1; i < n + 1; i++) {       while (tmp <= m && vis[tmp]) tmp++;       if (a[i] == -1) a[i] = b[tmp++];       cout << a[i] <<    n [i == n];     }     return 0;   }