malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct heap {     vector<pair<int, int> > v;     int loc[N];     heap() {       v.push_back(make_pair(-1, -1));       memset(loc, -1, sizeof loc);     }     void push(pair<int, int> p) {       int cur;       cur = v.size();       loc[p.second] = cur;       v.push_back(p);       while (v[cur] < v[cur >> 1]) {         swap(v[cur], v[cur >> 1]);         swap(loc[v[cur].second], loc[v[cur >> 1].second]);         cur >>= 1;       }     }     void pop() {       if (empty()) return;       swap(v[1], v.back());       loc[v[1].second] = 1;       loc[v.back().second] = -1;       v.pop_back();       int cur = 1;       while ((cur << 1) < v.size()) {         if ((cur << 1) + 1 == v.size()) {           if (v[cur] > v[cur << 1])             swap(v[cur], v[cur << 1]),                 swap(loc[v[cur].second], loc[v[cur << 1].second]);           break;         }         if (v[cur] < min(v[cur << 1], v[(cur << 1) + 1])) break;         if (v[cur << 1] < v[(cur << 1) + 1]) {           swap(v[cur], v[cur << 1]);           swap(loc[v[cur].second], loc[v[cur << 1].second]);           cur <<= 1;         } else {           swap(v[cur], v[(cur << 1) + 1]);           swap(loc[v[cur].second], loc[v[(cur << 1) + 1].second]);           cur = (cur << 1) + 1;         }       }     }     pair<int, int> top() { return v[1]; }     bool empty() { return v.size() == 1; }   };   int n, m;   vector<int> bad[N];   vector<pair<int, int> > v[N];   int d[N];   heap pq;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       --a, --b;       v[a].push_back(make_pair(b, c));       v[b].push_back(make_pair(a, c));     }     for (int i = 0; i < n; i++) {       int num;       cin >> num;       while (num--) {         int a;         cin >> a;         bad[i].push_back(a);       }     }     for (int i = 0; i < n; i++) d[i] = 0x3f3f3f3f;     d[0] = 0;     pq.push(make_pair(0, 0));     while (!pq.empty()) {       pair<int, int> tp = pq.top();       pq.pop();       int t = tp.first;       int cur = tp.second;       if (t != d[cur]) continue;       int j = 0;       while (j < bad[cur].size() && bad[cur][j] < t) j++;       while (j < bad[cur].size() && bad[cur][j] == t) t++, j++;       for (int i = 0; i < v[cur].size(); i++) {         int to = v[cur][i].first, cost = v[cur][i].second;         if (t + cost < d[to]) {           d[to] = t + cost;           pq.push(make_pair(d[to], to));         }       }     }     if (d[n - 1] >= 0x3f3f3f3f)       puts( -1 );     else       cout << d[n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1111;   const int INF = 0x7f7f7f7f;   int cases;   const double EPS = 1e-8;   inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }   int main() {     double s, a, b, c;     cin >> s >> a >> b >> c;     if (!sgn(a) && !sgn(b) && !sgn(c)) {       puts( 1.0 0.0 0.0 );     } else {       double ts = s / (a + b + c);       printf( %.10f %.10f %.10f n , a * ts, b * ts, c * ts);     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int cnt[4];   int main() {     int n;     scanf( %d , &n);     getchar();     for (int i = 0; i < n; ++i) {       char ch = getchar();       if (ch ==  A ) {         ++cnt[0];       } else if (ch ==  C ) {         ++cnt[1];       } else if (ch ==  G ) {         ++cnt[2];       } else if (ch ==  T ) {         ++cnt[3];       }     }     int mx = *max_element(cnt, cnt + 4);     int nMax = count(cnt, cnt + 4, mx);     long long ans = 1;     for (int i = 0; i < n; ++i) {       ans = (ans * nMax) % mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long MAX = 1e6 + 10;   long long a[100005];   int main() {     long long n, k, m, sum, t, len;     string s, d;     while (cin >> n) {       int flag = 1;       sum = 0;       if (n % 2 == 0) {         cout << n / 2 << endl;         for (long long i = (1); i <= (n / 2); ++i) cout <<  2  <<    ;         cout << endl;       } else {         cout << (n - 3) / 2 + 1 << endl;         for (long long i = (1); i <= ((n - 3) / 2); ++i) cout <<  2  <<    ;         cout <<  3  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200010], t;   int n;   long long b[200010];   int g[200010];   bool no[200010];   int main() {     scanf( %d %I64d , &n, &t);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       if (x < i) {         printf( No n );         return 0;       }       g[i]++;       g[x]--;       no[x] = 1;     }     int now = 0;     b[0] = 0;     for (int i = 1; i <= n; i++) {       now += g[i];       if (now > 0) {         if (no[i]) {           printf( No n );           return 0;         }         b[i] = max(a[i + 1] + t, b[i - 1] + 1);       } else {         b[i] = max(a[i] + t, b[i - 1] + 1);         if (no[i] && (b[i] >= a[i + 1] + t && i != n)) {           printf( No n );           return 0;         }       }     }     printf( Yes n );     for (int i = 1; i <= n; i++) printf( %I64d  , b[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 2e5 + 100;   long long dp[52][52][52];   bool vis[52][52][52];   long long val[52][52][52];   int a[maxn], w[maxn];   long long qmod(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       b >>= 1;       a = a * a % mod;     }     return ans;   }   int flag;   int dfs(int n, int i, int j, int k, long long p, long long v, long long sp,           long long sn) {     if (!n) {       return 1LL * p * v % mod;     }     if (vis[i][j][k]) {       return val[i][j][k] * qmod(dp[i][j][k], mod - 2) % mod * p % mod;     }     dp[i][j][k] = p;     val[i][j][k] +=         dfs(n - 1, i + 1, j, k,             1LL * p * sp % mod * qmod(v + sp + sn, mod - 2) % mod, v, sp + 1, sn);     val[i][j][k] += dfs(n - 1, i, j + 1, k,                         1LL * p * sn % mod * qmod(v + sp + sn, mod - 2) % mod, v,                         sp, max(sn - 1, 0LL));     val[i][j][k] += dfs(n - 1, i, j, k + 1,                         1LL * p * v % mod * qmod(v + sp + sn, mod - 2) % mod,                         max(v + flag, 0LL), sp, sn);     val[i][j][k] %= mod;     vis[i][j][k] = 1;     return val[i][j][k];   }   int main() {     ios::sync_with_stdio(false);     long long sn = 0, sp = 0;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       cin >> w[i];       if (a[i]) {         sp += w[i];       } else         sn += w[i];     }     for (int i = 0; i < n; ++i) {       memset(dp, 0, sizeof dp);       memset(vis, 0, sizeof vis);       memset(val, 0, sizeof val);       if (a[i]) {         flag = 1;         sp -= w[i];       } else {         flag = -1;         sn -= w[i];       }       cout << dfs(m, 0, 0, 0, 1, w[i], sp, sn) << endl;       if (a[i]) {         sp += w[i];       } else         sn += w[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int N = 200005;   const int M = 300;   const int OFF = N * M;   int _cnt[N + N * M];   int *cnt = _cnt + OFF;   int main() {     char s[N];     scanf( %s , s);     int n = strlen(s);     int psum[N];     for (int i = 0; i < n; i++) {       s[i] -=  0 ;       psum[i] = s[i];       if (i) psum[i] += psum[i - 1];     }     int sq = min(M, (int)sqrt(n));     ll ans = 0;     for (int j = 1; j < sq; j++) {       cnt[-1] = 1;       for (int i = 0; i < n; i++) {         int val = i - j * psum[i];         if (psum[i]) {           ans += cnt[val];         }         cnt[val]++;       }       for (int i = 0; i < n; i++) {         int val = i - j * psum[i];         cnt[val]--;       }     }     int nxt[N];     nxt[n] = n;     for (int i = n - 1; i >= 0; i--) {       nxt[i] = nxt[i + 1];       if (s[i] == 1) nxt[i] = i;     }     for (int i = 0; i < n; i++) {       int r = nxt[i];       int q = 1;       while (r < n && q * sq <= n - i) {         int p = nxt[r + 1];         int rig = max(r, i + q * sq - 1);         if (rig <= p) {           ans += (p - i) / q - (rig - i) / q;         }         r = p;         q++;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2005, MOD = 998244353;   char ch[MAXN];   long long cnt[MAXN], dp[MAXN][MAXN];   long long KSM(long long a, long long t) {     long long ans = 1;     while (t) {       if (t & 1) ans = ans * a % MOD;       t >>= 1;       a = a * a % MOD;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> (ch + 1);     int n = strlen(ch + 1);     for (int i = 1; i <= n; i++) cnt[i] = cnt[i - 1] + (ch[i] ==  ? );     for (int j = 1; j <= n; j++)       for (int i = j - 1; i; i--) {         if (ch[i] !=  )  && ch[j] !=  ( )           dp[i][j] =               (dp[i][j] + dp[i + 1][j - 1] + KSM(2, cnt[j - 1] - cnt[i])) % MOD;         if (ch[i] !=  ( ) dp[i][j] = (dp[i][j] + dp[i + 1][j]) % MOD;         if (ch[j] !=  ) ) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;         if (ch[i] !=  (  && ch[j] !=  ) )           dp[i][j] = (dp[i][j] - dp[i + 1][j - 1] + MOD) % MOD;       }     cout << dp[1][n];   }
#include <bits/stdc++.h>   int main() {     int i, j, l, x = 0;     char s[100005];     gets(s);     l = strlen(s);     for (i = 0, j = l - 1; i < l / 2; i++, j--) {       if (s[i] != s[j]) {         x = 1;         break;       }     }     if (x == 1) {       printf( NO n );     } else {       for (i = 0; i < l; i++) {         if (s[i] ==  A  || s[i] ==  H  || 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 ) {           x = 0;         } else {           x = 1;           break;         }       }       if (x == 1) {         printf( NO n );       } else {         printf( YES n );       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 2e3 + 5;   const long long MAX2 = 11;   const long long MOD = 998244353;   const long long MOD2 = 1000005329;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 2000;   int q, x, y, cnt;   map<string, pair<long long, long long>> ans, dp;   map<string, bool> jen;   map<string, vector<string>> isi;   string s, ty, c;   pair<long long, long long> solve(string o) {     if (!jen.count(o)) return ans[o];     if (isi[o].empty()) return {0, 0};     if (dp.count(o)) return dp[o];     int hit = isi[o].size() - 1;     long long mx = 0, ttl = 0;     pair<long long, long long> res;     if (jen[o]) {       for (auto i : isi[o]) {         res = solve(i);         mx = max(mx, res.second);         ttl += res.first;       }       return dp[o] = {ttl + 2 * ans[o].first + hit * ans[o].second,                       mx + 2 * ans[o].first};     }     {       for (auto i : isi[o]) {         res = solve(i);         mx = max(mx, res.first);         ttl += res.second;       }       return dp[o] = {mx + 2 * ans[o].first,                       ttl + 2 * ans[o].first + hit * ans[o].second};     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       cin >> ty;       x = y = cnt = 0;       if (ty ==  Widget ) {         cin >> s;         c =   ;         for (auto i : s) {           if (i ==  (  || i ==  )  || i ==  , )             ++cnt;           else if (cnt == 1)             x = x * 10 + i -  0 ;           else if (cnt == 2)             y = y * 10 + i -  0 ;           else             c.push_back(i);         }         ans[c] = {x, y};       } else if (ty ==  VBox ) {         cin >> s;         ans[s];         jen[s];       } else if (ty ==  HBox ) {         cin >> s;         ans[s];         jen[s] = 1;       } else {         s = c =   ;         for (auto i : ty) {           if (i ==  . )             ++cnt;           else if (i ==  ( ) {             if (c ==  pack )               cnt = 2;             else if (c ==  set_border )               cnt = 3;             else if (c ==  set_spacing )               cnt = 4;             c =   ;           } else if (i ==  ) )             continue;           else if (cnt == 0)             s.push_back(i);           else if (cnt == 1 || cnt == 2)             c.push_back(i);           else if (cnt == 3 || cnt == 4)             x = x * 10 + i -  0 ;           else             return 1;         }         if (cnt == 2)           isi[s].push_back(c);         else if (cnt == 3)           ans[s].first = x;         else           ans[s].second = x;       }     }     pair<long long, long long> res;     for (auto i : ans) {       res = solve(i.first);       cout << i.first <<     << res.first <<     << res.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e18;   int n, m, k, x, p;   int mat[1005][1005];   void solve(int tc) {     cin >> n >> m >> k >> p;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> mat[i][j];       }     }     multiset<int, greater<int> > msRow, msCol;     for (int r = 0; r < n; ++r) {       long long int rowSum = 0LL;       for (int i = 0; i < m; ++i) {         rowSum += mat[r][i];       }       msRow.insert(rowSum);     }     for (int c = 0; c < m; ++c) {       long long int colSum = 0LL;       for (int i = 0; i < n; ++i) {         colSum += mat[i][c];       }       msCol.insert(colSum);     }     vector<long long int> rows(k + 1, 0LL), cols(k + 1, 0LL);     for (int i = 1; i <= k; ++i) {       rows[i] = *msRow.begin();       msRow.erase(msRow.begin());       msRow.insert(rows[i] - (1LL * p * m));       rows[i] += rows[i - 1];       cols[i] = *msCol.begin();       msCol.erase(msCol.begin());       msCol.insert(cols[i] - (1LL * p * n));       cols[i] += cols[i - 1];     }     long long int ans = -inf;     for (int i = 0; i <= k; ++i) {       long long int tp = rows[i] + cols[k - i];       tp -= 1LL * p * i * (k - i);       if (tp > ans) ans = tp;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tt = 1;     for (int i = 1; i <= tt; ++i) {       solve(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long PR = 1000000009;   long long n, A[3][100009], dp[3][100009];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < 100009; i++)       A[0][i] = A[1][i] = A[2][i] = 0,       dp[0][i] = dp[1][i] = dp[2][i] = -1 * 10000000000000000ll;     for (int i = 0; i < n; i++) {       cin >> A[0][i];     }     for (int i = 0; i < n; ++i) cin >> A[1][i];     for (int i = 0; i < n; ++i) cin >> A[2][i];     dp[2][n] = 0;     for (int i = n - 1; i >= 0; i--) {       long long presum = A[0][i];       dp[0][i] = max(dp[0][i], presum + dp[0][i + 1]);       dp[2][i] = max(dp[2][i], A[2][i] + dp[2][i + 1]);       presum += A[1][i];       dp[0][i] = max(dp[0][i], presum + dp[1][i + 1]);       dp[2][i] = max(dp[2][i], A[2][i] + A[1][i] + dp[1][i + 1]);       presum += A[2][i];       dp[0][i] = max(dp[0][i], presum + dp[2][i + 1]);       dp[2][i] = max(dp[2][i], presum + dp[0][i + 1]);       presum += A[0][i + 1] + A[1][i + 1] + A[2][i + 1];       dp[2][i] = max(dp[2][i], presum + dp[0][i + 2]);       dp[0][i] = max(dp[0][i], presum + dp[2][i + 2]);       dp[1][i] = max(dp[1][i], A[1][i] + dp[1][i + 1]);       dp[1][i] = max(dp[1][i], A[1][i] + A[0][i] + dp[0][i + 1]);       dp[1][i] = max(dp[1][i], A[1][i] + A[2][i] + dp[2][i + 1]);     }     cout << dp[0][0] <<   n ;     return 0;   };
#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535;   const double eps = 1e-6;   struct TE {     int a, b, c;   } E[501000];   int tr[501000], n, x[501000], m;   bool cmp(TE a, TE b) { return a.a < b.a; }   int low(int a) { return (a & (-a)); }   int ask(int a) {     int ret = 1992837465;     while (a) {       ret = min(ret, tr[a]);       a -= low(a);     }     return ret;   }   void ins(int a, int b) {     while (a <= n + 5) {       tr[a] = min(tr[a], b);       a += low(a);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &E[i].a);     for (int i = 0; i < n; i++) scanf( %d , &E[i].b);     for (int i = 0; i < n; i++) scanf( %d , &E[i].c);     for (int i = 0; i < n; i++) {       E[i].a = -E[i].a;       E[i].b = -E[i].b;       E[i].c = -E[i].c;       x[i] = E[i].b;     }     sort(x, x + n);     m = unique(x, x + n) - x;     for (int i = 0; i < n; i++) E[i].b = (lower_bound(x, x + m, E[i].b) - x) + 1;     sort(E, E + n, cmp);     for (int i = 0; i <= n + 5; i++) tr[i] = 1992837465;     int ans = 0;     for (int i = 0; i < n; i++) {       int h = i;       while (i < n && E[i].a == E[h].a) {         if (ask(E[i].b - 1) < E[i].c) {           ans++;         }         i++;       }       i--;       for (int j = h; j <= i; j++) ins(E[j].b, E[j].c);     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   int n, u, v, x, trie[maxn << 1][26], sz[maxn << 1], tot, cnt[maxn], res;   char op[2];   int merge(int a, int b) {     if (!a || !b) return a + b;     int rt = ++tot;     memset(trie[rt], 0, sizeof trie[rt]);     sz[rt] = 1;     for (int i = 0; i < 26; ++i) {       trie[rt][i] = merge(trie[a][i], trie[b][i]);       sz[rt] += sz[trie[rt][i]];     }     return rt;   }   void dfs(int u, int dep) {     sz[u] = 1;     for (int i = 0; i < 26; ++i)       if (trie[u][i]) {         dfs(trie[u][i], dep + 1);         sz[u] += sz[trie[u][i]];       }     cnt[dep] += sz[u];     tot = n;     int rt = 0;     for (int i = 0; i < 26; ++i) rt = merge(rt, trie[u][i]);     cnt[dep] -= max(1, sz[rt]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       scanf( %d%d%s , &u, &v, op);       trie[u][op[0] -  a ] = v;     }     dfs(1, 0);     res = 0;     for (int i = 1; i < n; ++i)       if (cnt[i] > cnt[res]) res = i;     printf( %d n%d n , sz[1] - cnt[res], res + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int p = 1e9 + 7;   const int N = 1e5 + 1;   long long int fact[N];   long long int ncr[N];   long long int n_1cr[N];   void factorial() {     fact[0] = fact[1] = 1;     for (int i = 2; i < N; i++) {       fact[i] = i * fact[i - 1];       fact[i] %= p;     }   }   long long int fastPower(long long int a, long long int b) {     if (b == 0) return 1;     long long int tmp = fastPower(a, b / 2);     if (b & 1) return (tmp % p * tmp % p * a % p) % p;     return (tmp % p * tmp % p) % p;   }   long long int nCr(int n) {     ncr[0] = 1;     n_1cr[0] = 1;     for (int i = 1; i <= n; i++) {       long long int iPower = fastPower(i, p - 2);       ncr[i] = (ncr[i - 1] * (n - i + 1)) % p;       ncr[i] *= iPower;       ncr[i] %= p;       n_1cr[i] = (n_1cr[i - 1] % p * (n - i) % p) % p;       n_1cr[i] *= iPower;       n_1cr[i] %= p;     }   }   long long int nCr(int n, int r) {     long long ans = 1;     ans = (fact[n - r] * fact[r]) % p;     ans = (fact[n] * fastPower(ans, p - 2)) % p;     return ans;   }   int main() {     int n;     long long int sum = 0;     cin >> n;     factorial();     for (int i = 1; i <= n; i++) {       sum += nCr(n - 1, i - 1) * nCr(n, i);       sum %= p;     }     sum *= 2;     sum %= p;     sum -= n;     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, M;   vector<set<int> > A;   vector<set<pair<int, int> > > B;   vector<int> d, f, F, G;   vector<bool> v;   inline void upd(int& a, int b) {     if (d[a] > d[b]) a = b;   }   void ff(int x, int y) {     f[x] = x, v[x] = 1;     for (set<int>::iterator i = A[x].begin(); i != A[x].end(); i++)       if (v[*i]) {         if (*i != y) upd(f[x], *i);       } else         d[*i] = d[x] + 1, ff(*i, x), upd(f[x], f[*i]);   }   void ff(int x) {     f[x] = f[f[x]], v[x] = 0;     for (set<int>::iterator i = A[x].begin(); i != A[x].end(); i++)       if (v[*i]) ff(*i);   }   bool gg(int x, int y, int fa) {     if (x == y) return 1;     for (set<pair<int, int> >::iterator i = B[x].begin(); i != B[x].end(); i++)       if (i->first != fa)         if (gg(i->first, y, x)) {           v[i->second] = v[i->second ^ 1] = 1;           return 1;         }     return 0;   }   int main() {     scanf( %d%d , &n, &m);     A.resize(n);     for (int i = 0, x, y; i < m; i++)       scanf( %d%d , &x, &y), --x, --y, A[x].insert(y), A[y].insert(x);     if (n == 2) {       puts( -1 );       return 0;     }     d.resize(n, 0), f.resize(n), v.resize(n, 0);     ff(0, -1), ff(0);     F.resize(n);     for (int i = 0; i < n; i++)       if (f[i] == i) F[i] = (int)G.size(), G.push_back(i);     for (int i = 0; i < n; i++) F[i] = F[f[i]];     B.resize((int)G.size());     for (int i = 0; i < n; i++)       for (set<int>::iterator j = A[i].begin(); j != A[i].end(); j++)         if (F[i] != F[*j]) {           set<pair<int, int> >::iterator p =               B[F[i]].lower_bound(make_pair(F[*j], -1));           if (p != B[F[i]].end() && p->first == F[*j]) continue;           B[F[i]].insert(make_pair(F[*j], M++)),               B[F[*j]].insert(make_pair(F[i], M++));         }     if ((int)G.size() == 1) {       puts( 0 );       return 0;     }     if ((int)G.size() == 2) {       puts( 1 );       for (int i = 0; i < n; i++)         for (int j = i + 1; j < n; j++)           if (F[i] != F[j] && A[i].find(j) == A[i].end()) {             printf( %d %d n , i + 1, j + 1);             return 0;           }     }     vector<int> L;     for (int i = 0; i < (int)G.size(); i++)       if ((int)B[i].size() == 1) L.push_back(i);     printf( %d n , ((int)L.size() + 1) / 2);     while (1) {       random_shuffle(L.begin(), L.end());       bool F = 0, FF = 1;       if ((int)L.size() & 1) F = 1, L.push_back(L[0]);       v.clear(), v.resize(M, 0);       for (int i = 0; i < (int)L.size(); i += 2) gg(L[i], L[i + 1], -1);       for (int i = 0; i < M; i++)         if (!v[i]) {           FF = 0;           break;         }       if (FF) {         for (int i = 0; i < (int)L.size(); i += 2)           printf( %d %d n , G[L[i]] + 1, G[L[i + 1]] + 1);         return 0;       }       if (F) L.erase(L.end() - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) {       long long int n, i, j;       cin >> n;       long long int a[n + 5];       long long int b[n + 5];       unordered_map<long long int, long long int> rnk;       long long int ans = 0;       for (i = 0; i < n; i++) {         cin >> a[i];       }       j = 0;       for (i = 0; i < n; i++) {         cin >> b[i];         if (b[i] != a[j]) {           ans++;           rnk[b[i]]++;         } else {           j++;           while (j < n && rnk.find(a[j]) != rnk.end()) j++;         }       }       cout << ans <<   n ;     }     return 0;   }