malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m;   pair<long long, long long> seg[500000 + 1];   long long dp[20 + 1][500000 + 1];   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (long long i = 1; i < n + 1; i++) {       long long l, r;       cin >> l >> r;       seg[i] = {l, r};       if (dp[0][l] < r) {         dp[0][l] = r;       }     }     for (long long i = 1; i < 500000 + 1; i++) {       dp[0][i] = max(dp[0][i], dp[0][i - 1]);       if (dp[0][i] < i) dp[0][i] = 0;     }     for (long long i = 1; i < 20 + 1; i++) {       for (long long j = 0; j < 500000 + 1; j++) {         dp[i][j] = dp[i - 1][dp[i - 1][j]];         if (dp[i][j] < j) dp[i][j] = 0;       }     }     for (long long j = 1; j < m + 1; j++) {       long long x, y;       cin >> x >> y;       long long ans = 0;       for (long long i = 20; i >= 0; i--) {         if (dp[i][x] < y and dp[i][x] != 0) {           ans += (1 << i);           x = dp[i][x];         }       }       if (dp[0][x] >= y)         cout << ans + 1 <<   n ;       else         cout << -1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int param[51][51], n, targ;   vector<int> visted(51);   stack<int> s;   bool dfs(int root) {     if (root == targ) {       return true;     }     if (visted[root] == 0) s.push(root);     visted[root] = 1;     int nxt = -1;     for (int i = 1; i <= n; i++) {       if (param[root][i] == 1 && visted[i] == 0) {         nxt = i;       }     }     if (nxt == -1 && s.size() > 1) {       s.pop();       nxt = s.top();     }     if (nxt != -1)       dfs(nxt);     else       return false;   }   int GetNumberOfDigits(int i) { return i > 0 ? (int)log2(i) + 1 : 1; }   int main() {     int n, m, d, mx = 0, ret = 0;     vector<int> v;     cin >> n >> m;     for (int i = int(0); i < int(n); i++) {       cin >> d;       v.push_back(d);     }     int tm;     mx = m;     for (int i = int(0); i < int(n); i++) {       tm = m;       if (v[i] <= tm) {         ret = tm / v[i];         tm -= (ret * v[i]);       } else {         continue;       }       for (int j = int(i + 1); j < int(n); j++) {         int x = v[j] * ret + tm;         if (mx < x) mx = x;       }     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1e9 + 7;   const int N = 1e6 + 5, M = 1e5 + 10, NM1 = N - 1;   long long int OO = 1e18 + 8;   int oo = 1e9 + 8;   void readFile() {}   int n, m, l, r, x, top, arr[N], st[N];   long long int sum[N];   int main() {     readFile();     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , arr + i);     for (int i = 1; i <= n + 1; i++) {       while (arr[i] < arr[st[top]]) {         l = st[top] - st[top - 1];         r = i - st[top];         sum[1] += x = arr[st[top--]];         sum[l + 1] -= x;         sum[r + 1] -= x;         sum[l + r + 1] += x;       }       st[++top] = i;     }     for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];     for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d , &x);       printf( %0.12f n , (double)sum[x] / (n - x + 1.0));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k;     int v[200001];     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , v + i);     sort(v, v + n);     int l = 1;     int r = 1000000000;     int m;     for (int it = 0; l <= r and it < 50; it++) {       m = l + (r - l) / 2;       auto i = upper_bound(v, v + n, m);       if ((i - v) > k)         r = m;       else if ((i - v) == k)         break;       else         l = m + 1;     }     auto i = upper_bound(v, v + n, m);     if ((i - v) == k and (m > 0 and m <= 1000000000))       printf( %d n , m);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   vector<vector<int>> edges;   long long DP[200010];   long long fac[200010];   void solve(const int u, const int p) {     DP[u] = 1;     int tot = 0;     for (auto& e : edges[u]) {       if (e != p) {         tot++;         solve(e, u);         DP[u] = (DP[u] * DP[e]) % MOD;       }     }     DP[u] = (DP[u] * fac[tot]) % MOD;     if (u != 1 && tot) DP[u] = ((tot + 1) * DP[u]) % MOD;   }   int main() {     fac[0] = 1;     for (int i = 1; i <= 200000; i++) fac[i] = (fac[i - 1] * i) % MOD;     int N, t, f;     scanf( %d , &N);     edges.assign(N + 5, vector<int>());     for (int i = 0; i < N - 1; i++) {       scanf( %d %d , &t, &f);       edges[t].push_back(f);       edges[f].push_back(t);     }     solve(1, 1);     printf( %d n , int((N * DP[1]) % MOD));     return 0;   }
#include <bits/stdc++.h>   long long int lcm, k, ans, a, b;   using namespace std;   int main() {     int n;     cin >> n;     map<int, int> mp;     mp[n] = 1;     n++;     int c = 1;     while (1) {       if (mp[n] == 1 && n % 10 != 0)         break;       else {         if (n % 10 == 0) {           while (n % 10 == 0) n /= 10;         } else {           mp[n] = 1;           n++;           c++;         }       }     }     cout << c <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long md = 1e9 + 7;   long long r, b, i, x, y;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> r >> b;     for (i = 1; i <= r + b; i++) cin >> x >> y;     cout << (r == b ?  Yes  :  No ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, kecil, tamp1 = 0, tamp2 = 0, tambah = 0;     cin >> n;     cin >> m;     tamp1 = n;     tamp2 = m;     while (n != 0) {       n = tamp1;       if (tambah >= 1) m += tamp2;       if (m > n) {         cout << -1;         return 0;       }       for (int i = 0; i < m; i++) {         if (n == m - i)           n -= 1;         else           n -= 2;       }       tambah++;     }     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   void input(long long ara[], long long n) {     for (long long i = 0; i < n; i++) cin >> ara[i];   }   void output(long long ara[], long long n) {     for (long long i = 0; i < n; i++) cout << ara[i] <<    ;   }   long long mx1(long long ara[], long long n) {     long long mx = -1;     for (long long i = 0; i < n; i++)       if (ara[i] > mx) mx = ara[i];     return mx;   }   long long mn1(long long ara[], long long n) {     long long mn = 1e18;     for (long long i = 1; i <= n; i++)       if (ara[i] < mn) mn = ara[i];     return mn;   }   int maxSubArraySum(long long a[], long long size) {     long long max_so_far = INT_MIN, max_ending_here = 0;     for (long long i = 0; i < size; i++) {       max_ending_here = max_ending_here + a[i];       if (max_so_far < max_ending_here) max_so_far = max_ending_here;       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   int main() {     (ios_base::sync_with_stdio(false), cin.tie(NULL));     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ara[n + 1];       input(ara, n);       long long k = 0, sum = 0;       for (long long i = 0; i < n; i++) {         sum += ara[i];         if (sum <= 0) {           k = 1;         }       }       sum = 0;       for (long long i = n - 1; i >= 0; i--) {         sum += ara[i];         if (sum <= 0) {           k = 1;           break;         }       }       if (k == 1)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   __int128 read() {     __int128 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;   }   void print(__int128 x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   __int128 gcd(__int128 a, __int128 b) { return b ? gcd(b, a % b) : a; }   __int128 ex_gcd(__int128 a, __int128 b, __int128& x, __int128& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     __int128 d = ex_gcd(b, a % b, x, y);     __int128 temp = x;     x = y;     y = temp - a / b * y;     return d;   }   bool liEu(__int128 a, __int128 b, __int128 c, __int128& x, __int128& y) {     __int128 d = ex_gcd(a, b, x, y);     if (c % d != 0) return 0;     __int128 k = c / d;     x *= k;     y *= k;     return 1;   }   signed main() {     __int128 n, p, w, d;     n = read();     p = read();     w = read();     d = read();     __int128 x, y;     if (!liEu(w, d, p, x, y)) return (std::cout <<  -1 n , 0);     __int128 t = d / gcd(w, d);     __int128 xt = (x % t + t) % t;     __int128 yt = (p - w * xt) / d;     if (xt >= 0 && yt >= 0 && xt + yt <= n) {       print(xt);       printf(   );       print(yt);       printf(   );       print(n - xt - yt);       printf(  n );       return 0;     }     t = w / gcd(w, d);     yt = (y % t + t) % t;     xt = (p - d * yt) / w;     if (xt >= 0 && yt >= 0 && xt + yt <= n) {       print(xt);       printf(   );       print(yt);       printf(   );       print(n - xt - yt);       printf(  n );       return 0;     }     std::cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const double eps = 1e-6;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   const int maxn = 1e6 + 100;   long long qpow(long long a, long long b) {     long long ret = 1;     a %= mod;     while (b) {       if (b & 1) ret = ret * a % mod;       b /= 2;       a = a * a % mod;     }     return ret;   }   void solve() {     long long w, h;     scanf( %lld%lld , &w, &h);     cout << qpow(2LL, w + h) << endl;   }   int main() {     solve();     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string s;     cin >> s;     int depth = 0;     for (int i = 0; i < n; i++) {       depth += (s[i] ==  (  ? 1 : -1);     }     if (depth != 2 && depth != -2) {       cout <<  0 n ;       return 0;     }     if (depth == 2) {       depth = 0;       int ans = 0;       bool can = true;       for (int i = 0; i < n; i++) {         if (s[i] ==  ( ) {           if (depth - 1 >= 0) {             ans++;           }         }         depth += (s[i] ==  (  ? 1 : -1);         if (depth <= 1) {           ans = 0;         }         if (depth < 0) {           can = false;         }       }       if (!can) {         cout <<  0 n ;         return 0;       }       cout << ans <<   n ;     } else if (depth == -2) {       depth = 0;       int ans = 0;       bool can = true;       for (int i = 0; i < n; i++) {         if (s[i] ==  ) ) {           ans++;         }         depth += (s[i] ==  (  ? 1 : -1);         if (depth < 0) {           break;         }       }       depth = 0;       for (int i = 0; i < n; i++) {         depth += (s[i] ==  (  ? 1 : -1);         if (depth < -2) {           can = false;         }       }       if (!can) {         cout <<  0 n ;         return 0;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = int(1e9) + 7;   int n;   int a[100000], b[100000];   int who[200005];   bool used[200005] = {};   vector<int> g[200005];   int mul;   int far[200005];   int tr[200005];   void dfs(int v) {     ++mul;     used[v] = true;     for (int to : g[v]) {       dfs(to);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) {       scanf( %d%d , a + i, b + i);       --a[i];       --b[i];       g[b[i]].push_back(a[i]);     }     memset(who, -1, sizeof who);     for (int i = 0; i < (int)(n); ++i) who[a[i]] = i;     int ans = 1;     for (int i = 0; i < (int)(2 * n); ++i)       if (who[i] == -1) {         mul = 0;         dfs(i);         ans = (long long)ans * mul % MOD;       }     memset(far, -1, sizeof far);     for (int i = 0; i < (int)(n); ++i) far[a[i]] = b[i];     for (int _ = 0; _ < (int)(25); ++_)       for (int i = 0; i < (int)(2 * n); ++i) {         if (far[i] != -1) {           far[i] = far[far[i]];         }       }     for (int i = 0; i < (int)(n); ++i) tr[a[i]] = b[i];     for (int i = 0; i < (int)(2 * n); ++i)       if (far[i] != -1 && !used[far[i]]) {         int c = 0;         for (int x = far[i]; !used[x]; x = tr[x]) {           ++c;           used[x] = true;         }         if (c > 1) {           ans = 2ll * ans % MOD;         }       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 40;   int num[MAXN];   int a[MAXN];   int pref[MAXN];   bool isneg = false;   int n;   int max_k;   int mabs(int x) {     if (x < 0) {       return -x;     }     return x;   }   void neg() {     isneg = !isneg;     for (int i = 0; i < MAXN; ++i) {       num[i] = -num[i];       a[i] = -a[i];     }   }   void bin() {     int carry = 0;     for (int i = 0; i < MAXN; ++i) {       if (mabs(num[i] + carry) % 2 == 0) {         carry = (num[i] + carry) / 2;         num[i] = 0;       } else {         carry = (num[i] + carry - 1) / 2;         num[i] = 1;       }     }   }   void calc_pref() {     pref[0] = num[0];     for (int i = 1; i < MAXN; ++i) {       pref[i] = pref[i - 1] + num[i];     }   }   int cnt_ones(int from, int to) {     if (from < to) {       return 0;     }     return pref[from] - (to > 0 ? pref[to - 1] : 0);   }   void prepare_num() {     int carry = 0;     for (int i = 0; i < MAXN; ++i) {       if (mabs(num[i] + carry) % 2 == 0) {         carry = (num[i] + carry) / 2;       } else {         carry = (num[i] + carry - 1) / 2;       }     }     if (carry < 0) {       neg();     }     bin();   }   void add(int x, int power) {     int k = x < 0 ? -1 : 1;     x = k * x;     while (x != 0) {       num[power++] += k * (x % 2);       x /= 2;     }   }   bool try_for(int index) {     bool zero_allowed = index != n;     int a_i = a[index];     int k = a_i < 0 ? -1 : 1;     a_i *= k;     int carry = 0;     long long cur_num = 0;     int power = 0;     for (int i = 0; i <= 32; ++i) {       int cur_digit = num[index++] - k * (a_i % 2) + carry;       a_i /= 2;       if (mabs(cur_digit) % 2 == 0) {         carry = cur_digit / 2;       } else {         carry = (cur_digit - 1) / 2;         cur_num += 1ll << power;       }       ++power;       if (cnt_ones(MAXN - 1, index) == 0 && carry == -1) {         while (cur_num > 0) {           cur_num += 1ll << (power++);         }         break;       }     }     if (cnt_ones(MAXN - 1, index) != 0 || (carry != 0 && carry != -1) ||         cur_num > max_k || cur_num < -max_k || (cur_num == 0 && !zero_allowed)) {       return false;     } else {       return true;     }   }   int main() {     scanf( %d%d , &n, &max_k);     for (int i = 0; i <= n; ++i) {       scanf( %d , &a[i]);       add(a[i], i);     }     prepare_num();     calc_pref();     int ans = 0;     for (int i = 0; i <= n; ++i) {       if (cnt_ones(i - 1, 0) > 0) {         break;       }       ans += try_for(i);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 8, inf = 1e18 + 9, mod = 1e9 + 7;   char s[maxn];   long long n, m;   void solve() {     long long i, j, ans = 1;     cin >> n >> (s + 1);     for (i = 2; i <= n; i++)       if (s[i] != s[i - 1]) ans++;     cout << min(ans + 2, n) << endl;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     int x, y;     scanf( %d%d , &x, &y);     int i = 1;     while (1) {       if (y < 2 || ((100 * x) + (10 * y)) < 220) {         if (i & 1 == 1)           printf( Hanako );         else           printf( Ciel );         return 0;       }       if (i & 1 == 1) {         if (x >= 2) {           x -= 2;           y -= 2;         } else {           y -= ((220 - (100 * x))) / 10;           x = 0;         }       } else {         if (y >= 22)           y -= 22;         else if (y >= 12) {           x--;           y -= 12;         } else {           x -= 2;           y -= 2;         }       }       i++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   const long long maxn = 1e5 + 500;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 500;   long long out[maxn];   long long in[maxn];   long long a[maxn];   long long b[maxn];   long long dp[2][maxn];   int main() {     fill(out, out + maxn, -1);     fill(in, in + maxn, -1);     long long n, q, t;     cin >> n >> q >> t;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < q; i++) {       long long v, u;       cin >> v >> u;       v--;       u--;       out[u] = v;       in[v] = u;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         if (out[j] == -1) {           b[j] = a[j];         } else {           if (b[out[j]] != 0) {             b[j] = b[out[j]] + a[j];           }         }       }     }     for (long long i = 0; i < n; i++) {       if (b[i] == 0) {         cout << 0;         return 0;       }       if (in[i] != -1) {         t -= b[i];       }     }     if (t < 0) {       cout << 0;       return 0;     }     dp[1][0] = 1;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < b[i]; j++) {         dp[i & 1][j] = dp[(i & 1) ^ 1][j];       }       for (long long j = b[i]; j <= t; j++) {         dp[i & 1][j] =             ((long long)dp[(i & 1) ^ 1][j] + dp[(i & 1)][j - b[i]]) % mod;       }     }     cout << dp[(n - 1) & 1][t];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long n, k;       cin >> n >> k;       long long cur = 1, now = 1, ans = 0;       while (now <= k && cur < n) {         cur += now;         now <<= 1;         ans++;       }       if (cur < n) {         ans += (n - cur + k - 1) / k;       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int check(int p) {     int res;     res = a / p + b / p;     if (a / p == 0 || b / p == 0) return 0;     if (res >= n)       return 1;     else       return 0;   }   int main() {     int l, r, mid;     scanf( %d%d%d , &n, &a, &b);     r = a + b;     l = 1;     while (r - l > 1) {       mid = (r + l) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     printf( %d n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int u;     long long int cost;     node(int _u, long long int _cost) {       u = _u;       cost = _cost;     }     bool operator<(const node& p) const {       return (long long int)cost < (long long int)p.cost;     }   };   int numNodes, numEdges;   int source;   bool p;   vector<vector<int> > G;   map<pair<int, int>, int> cost;   vector<long long int> dist;   vector<int> par;   void clear() {     G.clear();     cost.clear();     dist.clear();   }   void dijstkra() {     priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,                    greater<pair<long long int, int> > >         q;     dist[source] = 0LL;     q.push({0LL, source});     while (!q.empty()) {       int u = q.top().second;       q.pop();       for (auto v : G[u]) {         if (dist[u] + cost[{u, v}] < dist[v]) {           dist[v] = dist[u] + cost[{u, v}];           par[v] = u;           q.push({dist[v], v});         }       }     }   }   void find_path(int s, int e) {     if ((s == e) || (e == -1)) {       if (p) cout <<    ;       p = true;       cout << s;     } else {       find_path(s, par[e]);       if (p) cout <<    ;       p = true;       cout << e;     }   }   int main() {     ios_base::sync_with_stdio(false);     p = false;     source = 1;     cin >> numNodes >> numEdges;     dist.resize(numNodes + 1, LLONG_MAX);     par.resize(numNodes + 1, -1);     G.resize(numNodes + 1);     for (int i = 1; i <= numEdges; i++) {       int u, v;       int w;       cin >> u >> v >> w;       G[u].push_back(v);       G[v].push_back(u);       cost[pair<int, int>(u, v)] = w;       cost[pair<int, int>(v, u)] = w;     }     dijstkra();     if (par[numNodes] == -1) {       cout <<  -1 n ;       return 0;     }     find_path(source, numNodes);     clear();   }
#include <bits/stdc++.h>   using namespace std;   int Id[2 * 105];   int L[2 * 105];   int W[2 * 105];   long long int dp[2 * 105][3005];   bool vis[2 * 105][3005];   int n, l;   long long int solve(int LastTp, int Len) {     if (Len > l) return 0LL;     if (Len == l) return 1LL;     if (vis[LastTp][Len] == 1) return dp[LastTp][Len];     vis[LastTp][Len] = 1;     long long int ret = 0;     for (int i = 1; i <= n; i++) {       if (Id[i] == Id[LastTp]) continue;       if (W[LastTp] == L[i]) ret = (ret + solve(i, Len + L[i])) % 1000000007;     }     return dp[LastTp][Len] = ret;   }   int main() {     int N, x, y;     scanf( %d %d , &N, &l);     for (int i = 1; i <= N; i++) {       scanf( %d %d , &x, &y);       L[++n] = x;       W[n] = y;       Id[n] = i;       if (x != y) {         L[++n] = y;         W[n] = x;         Id[n] = i;       }     }     long long int Sum = 0;     for (int i = 1; i <= n; i++) Sum = (Sum + solve(i, L[i])) % 1000000007;     cout << Sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     int n, cnt = 0;     cin >> n;     int a[100];     memset(a, 0, sizeof(a));     for (int i = 0; i < n; i++) {       int k, x = 0;       cin >> k;       while (k != 0) {         x = x + k % 10;         k = k / 10;       }       a[x]++;     }     for (int i = 1; i < 100; i++) {       while (a[i] > 0) {         a[i] = a[i] - 1;         for (int j = i; j < 100; j++) {           if (a[j] > 0 && (i + j) % 3 == 0) {             cnt++;             a[j]--;             break;           }         }       }     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000 + 5;   const int N = 2e5 + 5;   const long long oo = 1e18 + 5;   const long long mod = 998244353;   int a[N], b[N];   int mul(int a, int b) { return 1ll * a * b % mod; }   void solve() {     int n, k;     cin >> n >> k;     vector<int> pos(n + 2);     vector<int> lv(n + 2);     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       a[i] = x;       pos[x] = i;       lv[i] = 0;     }     for (int i = 1; i <= k; ++i) {       int x;       cin >> x;       b[i] = x;       lv[pos[x]] = i;     }     lv[0] = lv[n + 1] = INF;     int ans = 1;     for (int i = 1; i <= n; ++i) {       if (lv[i]) {         if (lv[i] > lv[i - 1] && lv[i] > lv[i + 1])           ans = mul(ans, 2);         else {           if (lv[i] <= lv[i - 1] && lv[i] <= lv[i + 1]) {             cout << 0 <<   n ;             return;           }         }       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }