malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int MOD = 1e9 + 7;   const int MOD2 = 1e9 + 9;   const int PR = 727;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   struct node {     int x;     int k;     int m;   };   const int N = 1e2 + 20;   const int M = 21;   long long dp[1 << M], n, m, b, ans = LINF;   node a[N];   bool cmp(node x, node y) { return x.k < y.k; }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> b;     for (int i = 0, mi; i < n; i++) {       cin >> a[i].x >> a[i].k >> mi;       for (int j = 0, x; j < mi; j++) {         cin >> x;         a[i].m += (1 << (x - 1));       }     }     sort(a, a + n, cmp);     memset(dp, 63, sizeof dp);     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (int mask = 1; mask < (1 << m); mask++)         if (mask & a[i].m)           dp[mask] = min(dp[mask], dp[mask ^ (mask & a[i].m)] + a[i].x);       ans = min(ans, (dp[(1 << m) - 1] == dp[(1 << M) - 1]                           ? LINF                           : dp[(1 << m) - 1] + a[i].k * b));     }     cout << (ans == LINF ? -1 : ans) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e6 + 50;   const int oo = 1e9;   const int mod = 1e9 + 7;   long long a[N];   int main() {     long long n, m;     cin >> n >> m;     long long c = 1;     int cur = 0;     for (int i = 30; i; i--) {       while (n >= (1 << i) - 1) {         for (int j = 1; j <= i; j++) a[cur++] = c;         c += m;         n -= (1 << i) - 1;       }     }     cout << cur << endl;     for (int i = 0; i < cur; i++) cout << a[i] <<    ;     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     string s;     cin >> s;     map<int, int> cnt;     for (int i = 0; i < s.size(); ++i) {       cnt[s[i] -  0 ]++;     }     cnt[1]--;     cnt[6]--;     cnt[8]--;     cnt[9]--;     string ans =   ;     for (int i = 1; i <= 9; ++i) {       for (int j = 0; j < cnt[i]; ++j) ans += (char)( 0  + i);     }     int powr = 1;     int su = 0;     for (int i = 0; i < ans.size(); ++i) {       su = su * 10 + (ans[i] -  0 );       su %= 7;     }     vector<int> perm = {1, 6, 8, 9};     do {       int n =           su * 10000 + perm[0] * 1000 + perm[1] * 100 + perm[2] * 10 + perm[3];       if (n % 7 == 0) {         cout << ans;         for (int x : perm) cout << x;         for (int i = 0; i < cnt[0]; ++i) cout << 0;         return 0;       }     } while (next_permutation(perm.begin(), perm.end()));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n, long long m) {     long long ret = n % m;     if (ret < 0) ret += m;     return ret;   }   long long gcd(long long a, long long b) {     return (b == 0LL ? a : gcd(b, a % b));   }   long long exp(long long a, long long b, long long m) {     if (b == 0LL) return 1LL;     if (b == 1LL) return mod(a, m);     long long k = mod(exp(a, b / 2, m), m);     if (b & 1LL) {       return mod(a * mod(k * k, m), m);     } else       return mod(k * k, m);   }   long long modpow(long long b, long long e, long long mod) {     long long ans = 1;     for (; e; b = b * b % mod, e /= 2)       if (e & 1) ans = ans * b % mod;     return ans;   }   const int N = 1e6 + 10;   int p[N];   bool vis[N];   int n;   int dp[2][N];   int cnt[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     vector<int> tam;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         int cur = p[i];         vis[cur] = 1;         int t = 1;         while (cur != i) {           t++;           cur = p[cur];           vis[cur] = 1;         }         tam.push_back(t);       }     }     int mx = 0;     int kk = k;     for (int x : tam) {       int poe = min(kk, x / 2);       kk -= poe;       mx += poe * 2;     }     mx += kk;     mx = min(mx, n);     for (int x : tam) cnt[x]++;     sort(tam.begin(), tam.end());     tam.erase(unique(tam.begin(), tam.end()), tam.end());     int tot = 0;     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     kk = 0;     for (int i = 1; i <= (int)tam.size(); i++) {       int val = tam[i - 1];       int prv = (i - 1) & 1;       int cur = (i & 1);       kk += val * cnt[val];       for (int j = 0; j <= kk; j++) {         if (dp[prv][j] >= 0)           dp[cur][j] = 0;         else if (j - val >= 0 and dp[cur][j - val] >= 0 and                  dp[cur][j - val] < cnt[val]) {           dp[cur][j] = dp[cur][j - val] + 1;         } else           dp[cur][j] = -1;       }     }     int mn = 0;     if (dp[(int)tam.size() & 1][k] != -1) {       mn = k;     } else       mn = min(n, k + 1);     cout << mn <<     << mx <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 1e6 + 7, K = 21, M = 1e9 + 7;   long long n;   signed dp[MAX_N][K][2];   long long get(long long x) {     if (x > n) return 0;     return (n / x);   }   signed main() {     memset(dp, 0, sizeof(dp));     cin >> n;     long long poww = 0, cur = 1;     while (cur * 2 <= n) {       cur *= 2;       poww++;     }     dp[1][poww][0] = 1;     if ((cur / 2) * 3 <= n) dp[1][poww - 1][1] = 1;     for (long long i = 1; i < n; i++) {       for (long long j = 0; j <= poww; j++) {         for (long long k = 0; k <= 1; k++) {           long long t = 1;           if (k == 1) t = 3;           dp[i + 1][j][k] =               (dp[i + 1][j][k] + dp[i][j][k] * (get((1 << j) * t) - i)) % M;           if (j > 0)             dp[i + 1][j - 1][k] =                 (dp[i + 1][j - 1][k] +                  dp[i][j][k] * (get((1 << (j - 1)) * t) - get((1 << j) * t))) %                 M;           if (k == 1)             dp[i + 1][j][0] = (dp[i + 1][j][0] +                                dp[i][j][k] * (get(1 << j) - get((1 << j) * t))) %                               M;         }       }     }     cout << dp[n][0][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void debug(int n, ...) {     va_list v1;     va_start(v1, n);     for (int i = 0; i < n; i++) {       int val = va_arg(v1, int);       printf( %d  , val);     }     va_end(v1);     printf(  n );   }   double n, k;   double sum;   int ans;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       double m;       cin >> m;       sum += m;     }     while (sum / (double)n < (k - 0.5)) {       sum += k;       ans++;       n++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int n, k, dep[N], fa[N];   bitset<N> s[2], t[4], a, b;   vector<bitset<N> > S;   inline bitset<N> qry(bitset<N> x, int y) {     y = min(y, n - 1);     char c[N];     putchar( ? );     for (int i = 1; i <= n; i++) printf(  %d , x[i] ? y : 0);     puts(  );     fflush(stdout);     scanf( %s , c + 1);     for (int i = 1; i <= n; i++)       if (c[i] ==  1 ) x[i] = 1;     return x;   }   int main() {     scanf( %d , &n);     while ((1 << k) <= n) k++;     s[0][1] = 1;     for (int i = 1; i <= n; i++) a[i] = 1;     S.push_back(a);     for (int i = k - 1; ~i; i--) {       int len = 1 << i;       for (int j = 0; j < 4; j++) t[j] = qry(s[j & 1], len - (j >> 1));       s[0] |= s[1];       s[1].reset();       vector<bitset<N> > nS;       for (int j = 0; j < S.size(); j++) {         a = t[j & 1] & S[j];         b = t[(j & 1) + 2] & S[j];         s[1] |= a ^ b;         nS.push_back(b);         nS.push_back(S[j] ^ b);       }       S = nS;     }     for (int i = 0; i < S.size(); i++)       for (int j = 1; j <= n; j++)         if (S[i][j]) dep[j] = i;     for (int i = 0; i < 3; i++)       for (int j = 0; j < k; j++) {         a.reset();         for (int x = 1; x <= n; x++) a[x] = (dep[x] % 3 == i && (x >> j & 1));         a = qry(a, 1);         for (int x = 1; x <= n; x++)           fa[x] |= ((dep[x] + 2) % 3 == i && a[x]) << j;       }     puts( ! );     for (int i = 2; i <= n; i++) printf( %d %d n , fa[i], i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n, m, a[N], b[N], t[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &a[i], &b[i]);     int x = a[1], cnt = 0;     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     x = b[1], cnt = 0;     memset(t, 0, sizeof(t));     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     x = a[2], cnt = 0;     memset(t, 0, sizeof(t));     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     x = b[2], cnt = 0;     memset(t, 0, sizeof(t));     for (int i = 1; i <= m; i++)       if (a[i] == x || b[i] == x) cnt++;     for (int i = 1; i <= m; i++) {       if (a[i] == x || b[i] == x) continue;       if (a[i] == b[i])         t[a[i]]++;       else         t[a[i]]++, t[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (t[i] + cnt == m) return puts( YES ), 0;     return puts( NO ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, pos[100001];   vector<int> d[100001];   void sieve() {     memset(d, 0, sizeof(d));     for (int i = 1; i < 100001; i++)       for (int j = i; j < 100001; j += i) d[j].push_back(i);     memset(pos, 0, sizeof(pos));   }   int main() {     sieve();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &x, &y);       if (y == 0) {         printf( %d n , d[x].size());         for (int j = 0; j < d[x].size(); j++) pos[d[x][j]] = i;         continue;       }       int Count = 0;       for (int j = 0; j < d[x].size(); j++) {         int num = d[x][j];         if (pos[num] < i - y) Count++;         pos[num] = i;       }       printf( %d n , Count);     }     return 0;   }
#include <bits/stdc++.h>   const long long inf = 1ll << 60;   const long long maxn = 30010;   using namespace std;   struct lsg {     long long x, y;   } a[maxn], b[maxn];   signed n, q, ffa[maxn], ffb[maxn], ban[maxn], x, y;   long long f[maxn], w1[maxn], w2[maxn], w3[maxn];   bool pd(lsg a, lsg b) { return a.x < b.x; }   inline void doit(long long i) {     w1[i] = w2[i] = w3[i] = -inf;     if (i >= 1 && ban[i] != i) w1[i] = a[i].x * b[i].x;     if (i >= 2 && ban[i] != i - 1 && ban[i - 1] != i)       w2[i] = a[i].x * b[i - 1].x + a[i - 1].x * b[i].x;     if (i >= 3) {       if (ban[i] != i - 2 && ban[i - 1] != i && ban[i - 2] != i - 1)         w3[i] =             a[i].x * b[i - 2].x + a[i - 1].x * b[i].x + a[i - 2].x * b[i - 1].x;       if (ban[i] != i - 1 && ban[i - 1] != i - 2 && ban[i - 2] != i)         w3[i] = max(w3[i], a[i].x * b[i - 1].x + a[i - 1].x * b[i - 2].x +                                a[i - 2].x * b[i].x);     }   }   inline signed read() {     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     signed k = 1, kk = 0;     if (c ==  - )       k = -1;     else       kk = c -  0 ;     c = getchar();     while (c >=  0  && c <=  9 ) kk = kk * 10 + c -  0 , c = getchar();     return k * kk;   }   inline long long max(long long x, long long y) { return x > y ? x : y; }   inline long long min(long long x, long long y) { return x < y ? x : y; }   signed main() {     n = read();     q = read();     for (signed i = 1; i <= n; i++) a[i].x = read(), a[i].y = i;     for (signed i = 1; i <= n; i++) b[i].x = read(), b[i].y = i;     sort(a + 1, a + 1 + n, pd), sort(b + 1, b + 1 + n, pd);     for (signed i = 1; i <= n; i++) ffa[a[i].y] = i, ffb[b[i].y] = i;     for (signed i = 1; i <= n; i++) ban[i] = ffb[a[i].y];     for (signed i = 1; i <= n; i++) doit(i);     for (signed j = 1; j <= q; j++) {       x = ffa[read()], y = ffa[read()], swap(ban[x], ban[y]);       for (signed i = max(1, x - 5); i <= min(n, x + 5); i++) doit(i);       for (signed i = max(1, y - 5); i <= min(n, y + 5); i++) doit(i);       f[0] = 0;       for (signed i = 1; i <= n; i++) {         if (i >= 1) f[i] = f[i - 1] + w1[i];         if (i >= 2) f[i] = max(f[i], f[i - 2] + w2[i]);         if (i >= 3) f[i] = max(f[i], f[i - 3] + w3[i]);       }       cout << f[n] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, c[105];   int sum[105][10005], h[105][10005], f[105][10005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);       sum[i][0] = 0;       for (int j = 1; j <= c[i]; j++) {         int x;         scanf( %d , &x);         sum[i][j] = sum[i][j - 1] + x;       }       for (int j = 1; j <= c[i]; j++)         for (int k = 0; k <= j; k++)           h[i][j] = max(h[i][j], sum[i][k] + sum[i][c[i]] - sum[i][c[i] - j + k]);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 0; k <= min(j, c[i]); k++)           f[i][j] = max(f[i][j], f[i - 1][j - k] + h[i][k]);     printf( %d n , f[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> nums(n);     vector<string> nums_str(n);     unordered_map<string, int> counts;     for (int i = 0; i < n; i++) {       cin >> nums[i];       nums_str[i] = to_string(nums[i]);       unordered_map<string, bool> used;       for (int l = 1; l <= 9; l++) {         for (int j = 0; j <= 9 - l; j++) {           string part = nums_str[i].substr(j, l);           if (used.find(part) == used.end()) {             used[part] = true;             if (counts.find(part) == counts.end()) counts[part] = 0;             counts[part]++;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int l = 1; l <= 9; l++) {         for (int j = 0; j <= 9 - l; j++) {           string part = nums_str[i].substr(j, l);           if (counts[part] == 1) {             cout << part <<   n ;             goto end_number;           }         }       }     end_number : {}     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, ans, a[500001], f[2][1200001];   int main() {     scanf( %lld , &n);     f[0][0] = 1;     for (i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       a[i] ^= a[i - 1];       ans += f[i % 2][a[i]];       f[i % 2][a[i]]++;     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long int fac(long long int n) {     long long int g = 1;     for (int x = 1; x <= n; x++) g *= x;     return g;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int g[25] = {0};       long long int f = 2;       long long int r = 0;       while (n > 0) {         ++g[n % f];         n /= f;         ++f;         ++r;       }       long long int ans = 0;       for (int x = 1; x < 25; x++) {         if (g[x] > 0) {           long long int e[25] = {0};           e[0] = g[0];           for (int y = 1; y < 25; y++) {             if (y != x)               e[y] = e[y - 1] + g[y];             else               e[y] = e[y - 1] + g[y] - 1;           }           long long int h = 0;           long long int k = 1;           for (int y = 0; y < r - 1; y++) {             k *= (e[y + 1] - h);             ++h;           }           for (int y = 0; y < 25; y++) {             if (x != y)               k /= fac(g[y]);             else               k /= fac(g[y] - 1);           }           ans += k;         }       }       cout << ans - 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long q, m, n, i, j, dummy, a, b, x, y, t, x1, y1;     cin >> n >> m >> q;     vector<vector<long> > R(100, vector<long>(100, 0));     vector<vector<long> > C(100, vector<long>(100, 0));     vector<vector<long> > E(100, vector<long>(100, 0));     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         R[i][j] = i;         C[i][j] = j;       }     }     for (dummy = 0; dummy < q; dummy++) {       cin.ignore();       cin >> t >> b;       if (t == 1) {         x1 = R[b - 1][0];         y1 = C[b - 1][0];         for (j = 0; j < m - 1; j++) {           R[b - 1][j] = R[b - 1][j + 1];           C[b - 1][j] = C[b - 1][j + 1];         }         R[b - 1][m - 1] = x1;         C[b - 1][m - 1] = y1;       }       if (t == 2) {         x1 = R[0][b - 1];         y1 = C[0][b - 1];         for (i = 0; i < n - 1; i++) {           R[i][b - 1] = R[i + 1][b - 1];           C[i][b - 1] = C[i + 1][b - 1];         }         R[n - 1][b - 1] = x1;         C[n - 1][b - 1] = y1;       }       if (t == 3) {         x = b;         cin >> y >> a;         x1 = R[x - 1][y - 1];         y1 = C[x - 1][y - 1];         E[x1][y1] = a;       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cout << E[i][j];         cout <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long losn = 1e6 + 5;   const long long maxn = 1e5 + 5;   const long long minn = 1e3 + 5;   const long long tiny = 1e2 + 5;   const long long inf = 1e9;   const long long mod = 1e9 + 7;   const long long hmod = 4698571;   long long n;   char c[maxn * 2];   map<pair<long long, long long>, long long> mp;   int main() {     long long t;     cin >> t;     while (t--) {       cin >> n;       long long ansl = 1, ansr = n;       scanf(  %s , c + 1);       long long anslen = inf;       mp.clear();       long long x = 0, y = 0;       pair<long long, long long> ps(x, y);       mp[ps] = 0;       for (long long i = 1; i <= n; i++) {         if (c[i] ==  L ) {           x--;         } else if (c[i] ==  R ) {           x++;         } else if (c[i] ==  D ) {           y--;         } else if (c[i] ==  U ) {           y++;         }         pair<long long, long long> p(x, y);         if (mp.count(p)) {           long long len = i - mp[p];           if (len < anslen) {             anslen = len;             ansl = mp[p] + 1;             ansr = i;           }         }         mp[p] = i;       }       if (anslen != inf) {         cout << ansl <<     << ansr << endl;       } else {         cout << -1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int lcs(string X, string Y) {     int i, j, m = X.length(), n = Y.length();     int L[m + 1][n + 1];     for (i = 0; i <= m; i++) {       for (j = 0; j <= n; j++) {         if (i == 0 || j == 0)           L[i][j] = 0;         else if (X[i - 1] == Y[j - 1])           L[i][j] = L[i - 1][j - 1] + 1;         else           L[i][j] = max(L[i - 1][j], L[i][j - 1]);       }     }     return L[m][n];   }   int main() {     long long n;     cin >> n;     vector<long long> v;     string x, y;     x = to_string(n);     int max = 0;     for (long long i = 1; i <= sqrt(n); i++) {       v.push_back(i * i);       y = to_string(i * i);       if (max < lcs(x, y) && (lcs(x, y) == y.length())) {         max = lcs(x, y);       }     }     if (max != 0) {       cout << x.length() - max;     } else {       cout <<  -1 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int K = 1e6 + 6;   const int mod = 1e9 + 7;   int n, k;   int val[K];   int ans, cur;   int power(int a, int b) {     int res = 1;     while (b) {       if (b & 1) {         res = (1LL * res * a) % mod;       }       a = (1LL * a * a) % mod;       b >>= 1;     }     return res;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= k + 2; ++i) {       val[i] = (val[i - 1] + power(i, k)) % mod;     }     if (n <= k + 2) {       printf( %d n , val[n]);       return 0;     }     ans = 0;     cur = 1;     for (int i = 2; i <= k + 2; ++i) {       cur = (1LL * cur * (n - i)) % mod;       cur = (1LL * cur * power(mod + 1 - i, mod - 2)) % mod;     }     for (int i = 1; i <= k + 2; ++i) {       ans = (ans + 1LL * cur * val[i]) % mod;       cur = (1LL * cur * (n - i)) % mod;       cur = (1LL * cur * (i - k - 2 + mod)) % mod;       cur = (1LL * cur * power((1LL * (n - i - 1) * i) % mod, mod - 2)) % mod;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int mm = 2e5 + 30;   long long a1, a2, a3, a4, a5, a6, a7, a8, a9, ez1, ans, n, m, k, sum;   string s, s1, s2, s3;   int flag[mm];   bool y = 0;   bool omm(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   void input() { cin >> n; }   void solve() {     for (int i = 1; i <= n; i++) {       cin >> ez1;       flag[ez1] = i;     }     int l = 0;     for (int i = 0; i < n; i++) {       cin >> ez1;       if (flag[ez1] < l) {         cout << 0 <<    ;       } else {         cout << abs(flag[ez1] - l) <<    ;         l = flag[ez1];       }     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     input();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MOD = 998244353;   int add(int x, int y) { return (x + y) % MOD; }   int sub(int x, int y) { return (x + MOD - y) % MOD; }   int mul(int x, int y) { return (1ll * x * y) % MOD; }   int modpow(int base, int exp) {     base %= MOD;     int result = 1;     while (exp > 0) {       if (exp & 1) result = (1ll * result * base) % MOD;       base = (1ll * base * base) % MOD;       exp >>= 1;     }     return result;   }   int modinv(int a) { return modpow(a, MOD - 2); }   int divide(int x, int y) { return mul(x, modinv(y)); }   int n, m;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     int rlen = 0;     int roll1 = 1, roll2 = n + m;     for (int i = 1; i <= n + 1; ++i) {       rlen = add(rlen, divide(mul(roll1, i), roll2));       roll1 = mul(roll1, n + 1 - i);       roll2 = mul(roll2, n + m - i);     }     rlen = mul(rlen, m);     int I = 1;     for (int i = 1; i <= n; ++i) {       I = add(I, divide(m, i));     }     cout << mul(rlen, I) << endl;     return 0;   }