malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 6100, EMAX = 13000, VMAX = 6100;   struct Edge {     int x;     int y;     int next;   };   int N, R[NMAX], ans;   short f[NMAX][NMAX], g[NMAX][NMAX];   int V[VMAX], eid;   Edge E[EMAX];   void insert(int x, int y) {     E[++eid] = (Edge){x, y, V[x]};     V[x] = eid;   }   int calc(int x, int y) {     int i, j, res = max(f[x][0], g[y][0]);     for (i = 1, j = g[y][0]; i <= f[x][0]; i += 1) {       while (j && R[f[x][i]] >= R[g[y][j]]) j -= 1;       res = max(res, i + j);     }     return res;   }   void DFS(int pre, int x) {     int i, j, y, l, r, m;     f[x][0] = g[x][0] = 1;     f[x][1] = g[x][1] = x;     for (i = V[x]; i; i = E[i].next) {       if ((y = E[i].y) == pre) continue;       DFS(x, y);       ans = max(ans, calc(x, y));       ans = max(ans, calc(y, x));       if (R[x] <= R[f[y][1]])         f[y][1] = x;       else if (R[f[y][f[y][0]]] < R[x])         f[y][++f[y][0]] = x;       else {         for (l = 1, r = f[y][0]; l + 1 < r;) {           m = (l + r) >> 1;           if (R[f[y][m]] < R[x])             l = m;           else             r = m;         }         f[y][r] = x;       }       if (R[x] >= R[g[y][1]])         g[y][1] = x;       else if (R[g[y][g[y][0]]] > R[x])         g[y][++g[y][0]] = x;       else {         for (l = 1, r = g[y][0]; l + 1 < r;) {           m = (l + r) >> 1;           if (R[g[y][m]] > R[x])             l = m;           else             r = m;         }         g[y][r] = x;       }       f[x][0] = max(f[x][0], f[y][0]);       g[x][0] = max(g[x][0], g[y][0]);       for (j = 1; j <= f[y][0]; j += 1) {         f[x][j] = f[x][j] && R[f[x][j]] < R[f[y][j]] ? f[x][j] : f[y][j];       }       for (j = 1; j <= g[y][0]; j += 1) {         g[x][j] = g[x][j] && R[g[x][j]] > R[g[y][j]] ? g[x][j] : g[y][j];       }     }   }   int main() {     int i, x, y;     scanf( %d , &N);     for (i = 1; i <= N; i += 1) scanf( %d , &R[i]);     for (i = 1; i < N; i += 1) {       scanf( %d %d , &x, &y);       insert(x, y);       insert(y, x);     }     DFS(-1, 1);     printf( %d n , ans);     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     int a[3007];     while (~scanf( %d , &n)) {       for (i = 0; i < n; i++) scanf( %d , &a[i]);       sort(a, a + n);       for (i = 0; i < n; i++)         if (a[i] != i + 1) break;       printf( %d n , i + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   stringstream ss;   long long p[1000010], h1[1000010], h2[1000010];   int main() {     p[0] = 1;     for (int i = 1; i < 1000010; i++) h1[i] = p[i] = p[i - 1] * 127LL;     int n, m, a, b;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       h1[a] += p[b];       h2[a] += p[b];       h1[b] += p[a];       h2[b] += p[a];     }     sort(h1 + 1, h1 + 1 + n);     sort(h2 + 1, h2 + 1 + n);     long long res = 0;     for (int i = 1; i <= n; i++) {       long long cnt = 1;       while (i + 1 <= n && h1[i] == h1[i + 1]) cnt++, i++;       res += (cnt) * (cnt - 1) / 2LL;     }     for (int i = 1; i <= n; i++) {       long long cnt = 1;       while (i + 1 <= n && h2[i] == h2[i + 1]) cnt++, i++;       res += (cnt) * (cnt - 1) / 2LL;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 123;   char res[maxn][maxn];   int a[maxn];   int n;   int sumx, maxy, miny, nowy;   int main() {     scanf( %d , &n);     sumx = maxy = miny = nowy = 0;     int flag = 1;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       sumx += a[i];       nowy += flag * a[i];       flag = -flag;       if (nowy > maxy) maxy = nowy;       if (nowy < miny) miny = nowy;     }     for (int i = 0; i < maxy - miny; ++i)       for (int j = 0; j < sumx; ++j) res[i][j] =    ;     int py = maxy - 1, px = 0;     flag = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < a[i]; ++j) {         if (flag == 1)           res[py][px] =  / ;         else           res[py][px] =     ;         px++;         if (j != a[i] - 1) py -= flag;       }       flag = -flag;     }     for (int i = 0; i < maxy - miny; ++i, puts(  ))       for (int j = 0; j < sumx; ++j) putchar(res[i][j]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 1010, P = 1e9 + 7;   template <class T>   inline bool chkmin(T &A, T B) {     return B < A ? A = B, 1 : 0;   }   template <class T>   inline bool chkmax(T &A, T B) {     return A < B ? A = B, 1 : 0;   }   template <class T, class _>   inline void Add(T &first, _ second) {     first += second;     if (first >= P) first -= P;     if (first < 0) first += P;   }   int n, K;   long long C[N][N], Fac[N], dp[N][N];   int main() {     int cas;     Fac[0] = 1;     for (int i = (1), i_end = (N - 10); i <= i_end; ++i)       Fac[i] = Fac[i - 1] * i % P;     for (int i = (0), i_end = (N - 10); i <= i_end; ++i) {       C[i][0] = 1;       for (int j = (1), j_end = (i); j <= j_end; ++j)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P;     }     dp[0][0] = 1;     for (int i = (1), i_end = (N - 10); i <= i_end; ++i)       for (int j = (1), j_end = (i); j <= j_end; ++j)         dp[i][j] = (dp[i - j][j] + dp[i - j][j - 1]) % P;     scanf( %d , &cas);     while (cas--) {       long long ans = 0;       scanf( %d%d , &n, &K);       for (int i = (K * (K + 1) / 2), i_end = (n); i <= i_end; ++i)         Add(ans, dp[i][K] * C[n - i + K][K] % P);       printf( %lld n , ans * Fac[K] % P);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int binarySearch(long long int arr[], long long int l, long long int r,                    long long int x) {     if (r >= l) {       long long int mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     long long int t;     cin >> t;     while (t--) {       long long int n, x;       cin >> n >> x;       long long int a[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       long long int ans = 0;       if (binarySearch(a, 0, n - 1, x) != -1) {         ans = 1;       } else {         if (x % a[n - 1] == 0) {           ans = x / a[n - 1];         } else {           if (x / a[n - 1] == 0) {             ans++;           }           ans += x / a[n - 1] + 1;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     double u, v, w, x, y, l = 1e9, r = 0;     cin >> n >> w >> v >> u;     while (n--) {       cin >> x >> y;       l = min(l, x - y / u * v);       r = max(r, x - y / u * v);     }     cout << fixed << setprecision(6) << w / u + r / v * (l < 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long n, k, cnt = 0, flag = 0;     cin >> n >> k;     if (n > k * (k - 1)) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (long long i = 1; i <= k; i++) {       for (long long j = i + 1; j <= k; j++) {         cout << i <<     << j <<   n ;         cnt++;         if (cnt >= n) {           flag = 1;           break;         }         cout << j <<     << i <<   n ;         cnt++;         if (cnt >= n) {           flag = 1;           break;         }       }       if (flag) break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;       #define int long long   //#define int unsigned int   //#define pb push_back   //#define mp make_pair   #define mod 1000000007   #define double long double   #define all(x) x.begin(), x.end()   #define debug(x) cout << #x <<   =   << x <<   n    const int inf=1e18;   const int maxu=200005;   //int d;   //vector <int> adj[maxu];     //vector <int> vis(maxu);   //vector <vector <int>> v(maxu);      /*int fun(int a,int b){       if(b==0)return 1;       else if(a==1)return 1;       int temp=fun(a,b/2)%mod;       temp=(temp*temp)%mod;        if(b%2==1)temp=(temp*a)%mod;       return temp%mod;   }       int inv(int a,int b){       return (a*fun(b,mod-2))%mod;   }      void dfs(int s){       if(vis[s])return;       vis[s]=1;       for(auto u:adj[s]){           dfs(u);       }   }*/          signed main()   {   /*        #ifndef ONLINE_JUDGE       freopen( inputhsr.txt ,  r , stdin);        freopen( outputhsr.txt ,  w , stdout);       #endif       */       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);          int i,j,k=0,n,t=1,m,l=0;                            //cin>>t;       while(t--){           cin>>n;                      int a[n+1];                      for(i=1;i<=n;i++)cin>>a[i];                      vector <vector<int>> v;                      for(i=1;i<=n;i++){               for(j=i+1;j<=n;j++){                   int val=abs(a[j]-a[i]);                   if(a[i]<a[j]){                       vector <int> v1={val,j,i};                       v.push_back(v1);                   }                   else{                       vector <int> v1={val,i,j};                       v.push_back(v1);                                          }                                                     }           }                      sort(all(v));           reverse(all(v));                      int ans=false;                      for(auto u:v){               cout<< ?  <<u[1]<<   <<u[2]<<endl;               string s;               cin>>s;               if(s== Yes ){                   cout<< !  <<u[1]<<   <<u[2]<<endl;                   ans=true;break;               }           }                      if(!ans){               cout<< !  <<0<<   <<0<<endl;           }                      /*          for(i=0;i<=n;i++)vis[i]=0;          for(i=0;i<=n;i++){               adj[i].clear();          }          */                     /*string s;           cin>>s;           n=s.length();*/              //memset(a,0,sizeof(a));           //cout<<fixed<<setprecision(10)<<ans<<  n ;                 }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {     int dx1 = b.first - a.first;     int dy1 = b.second - a.second;     int dx2 = c.first - a.first;     int dy2 = c.second - a.second;     return 1ll * dx1 * dy2 - 1ll * dy1 * dx2;   }   long long dist(pair<int, int> a, pair<int, int> b) {     int dx = b.first - a.first;     int dy = b.second - a.second;     return 1ll * dx * dx + 1ll * dy * dy;   }   pair<int, int> a[5005];   int n;   vector<pair<int, int> > hull;   long long mxarea = 0;   int r1, r2, r3;   void solve() {     for (int i = 0; i + 2 < hull.size(); i++) {       int p2 = i + 1, p3 = i + 2;       while (p2 + 1 < hull.size()) {         p3 = max(p3, p2 + 1);         while (p3 + 1 < hull.size() && ccw(hull[i], hull[p2], hull[p3]) <                                            ccw(hull[i], hull[p2], hull[p3 + 1])) {           p3++;         }         if (mxarea < ccw(hull[i], hull[p2], hull[p3])) {           mxarea = ccw(hull[i], hull[p2], hull[p3]);           tie(r1, r2, r3) = make_tuple(i, p2, p3);         }         p2++;       }     }     int x1 = hull[r1].first + hull[r2].first - hull[r3].first;     int x2 = hull[r2].first + hull[r3].first - hull[r1].first;     int x3 = hull[r3].first + hull[r1].first - hull[r2].first;     int y1 = hull[r1].second + hull[r2].second - hull[r3].second;     int y2 = hull[r2].second + hull[r3].second - hull[r1].second;     int y3 = hull[r3].second + hull[r1].second - hull[r2].second;     printf( %d %d n%d %d n%d %d , x1, y1, x2, y2, x3, y3);   }   int main() {     long long x;     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     swap(a[0], *min_element(a, a + n));     sort(a + 1, a + n, [&](const pair<int, int> &aa, const pair<int, int> &bb) {       long long t = ccw(a[0], aa, bb);       if (t != 0) return t > 0;       return dist(a[0], aa) < dist(a[0], bb);     });     for (int i = 0; i < n; i++) {       while (hull.size() >= 2 &&              ccw(hull[hull.size() - 2], hull.back(), a[i]) <= 0) {         hull.pop_back();       }       hull.push_back(a[i]);     }     solve();   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       printf( ? %d %d n , i, n);       fflush(stdout);       scanf( %d , &a[i]);     }     for (int i = 1; i < n - 1; i++) a[i] -= a[i + 1];     printf( ? %d %d n , n - 2, n - 1);     fflush(stdout);     int v;     scanf( %d , &v);     v -= a[n - 2];     a[n] = a[n - 1] - v;     a[n - 1] = v;     printf( !  );     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const nmax = 100000;   int const domain = 1000000;   struct Person {     int x;     int v;     bool operator<(Person other) const { return (x < other.x); }   };   int n, nl, nr;   int s;   Person pl[1 + nmax], pr[1 + nmax];   bitset<1 + domain> okl, okr;   double timetodest(int distp, int vp, int distray) {     double timep = 1.0L * distp / vp;     double timehit = 1.0L * (distray - distp) / (s - vp);     if (timep <= timehit)       return timep;     else {       double disthit = distp - timehit * vp;       return timehit + (disthit / (vp + s));     }   }   void checktime(double target, Person *p, int np, bitset<1 + domain> *ok) {     for (int i = 1; i <= np; i++) {       if (p[i].x <= p[i].v * target) {         for (int j = 1; j < domain; j++) (*ok)[j] = 1;         return;       }     }     int i = 1;     for (int j = 1; j < domain; j++) {       bool flag = false;       while (flag == false && i <= np && p[i].x <= j) {         if (timetodest(p[i].x, p[i].v, j) <= target)           flag = true;         else           i++;       }       (*ok)[j] = flag;     }   }   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       int x, v, dir;       cin >> x >> v >> dir;       if (dir == 1) {         nl++;         pl[nl] = {x, v};       } else {         nr++;         pr[nr] = {domain - x, v};       }     }     sort(pl + 1, pl + nl + 1);     sort(pr + 1, pr + nr + 1);     double t1 = 0, t2 = domain, tmid;     double deltat = 1;     double stop = 0.0000000001L;     while (stop < deltat) {       tmid = (t1 + t2) / 2;       deltat = (tmid - t1) / 2;       checktime(tmid, pl, nl, &okl);       checktime(tmid, pr, nr, &okr);       int flag = 0, j = 1;       while (flag == 0 && j < domain) {         if (okl[j] == 1 && okr[domain - j] == 1) flag = 1;         j++;       }       if (flag == 1)         t2 = tmid;       else         t1 = tmid;     }     cout << fixed << setprecision(12) << tmid <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, a[N], maxi[4 * N];   pair<int, int> p[N];   vector<int> v[3];   bool cmp(pair<int, int> p1, pair<int, int> p2) {     if (p1.first == p2.first)       return p1.second > p2.second;     else       return p1.first < p2.first;   }   void merge(int at) { maxi[at] = max(maxi[2 * at], maxi[2 * at + 1]); }   void build(int at, int L, int R) {     if (L == R) {       maxi[at] = 0;       return;     }     int mid = (L + R) / 2;     build(2 * at, L, mid);     build(2 * at + 1, mid + 1, R);     merge(at);   }   void update(int at, int L, int R, int pos, int val) {     if (L == R) {       maxi[at] = val;       return;     }     int mid = (L + R) / 2;     if (pos <= mid)       update(2 * at, L, mid, pos, val);     else       update(2 * at + 1, mid + 1, R, pos, val);     merge(at);   }   int query(int at, int L, int R, int l, int r) {     if (r < L || l > R) return 0;     if (l <= L && r >= R) return maxi[at];     int mid = (L + R) / 2;     int x = query(2 * at, L, mid, l, r);     int y = query(2 * at + 1, mid + 1, R, l, r);     return max(x, y);   }   int main() {     int n, n1, n2, n3, q, x;     scanf( %d %d %d , &n1, &n2, &n3);     ;     n = n1 + n2 + n3;     for (int j = 0; j < n1; j++) {       scanf( %d , &x);       v[0].push_back(x);     }     for (int j = 0; j < n2; j++) {       scanf( %d , &x);       v[1].push_back(x);     }     for (int j = 0; j < n3; j++) {       scanf( %d , &x);       v[2].push_back(x);     }     for (int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());     int cnt = 0;     for (int i = 0; i < 3; i++) {       for (int u : v[i]) {         p[cnt] = make_pair(u, cnt);         cnt++;       }     }     sort(p, p + n, cmp);     build(1, 0, n - 1);     int maxi = 0;     for (int i = 0; i < n; i++) {       int tmp = query(1, 0, n - 1, 0, p[i].second - 1);       maxi = max(maxi, tmp + 1);       update(1, 0, n - 1, p[i].second, tmp + 1);     }     printf( %d n , n - maxi);   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9, PI = acos(-1.);   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   const int N = 1e5 + 5;   int n, x, v;   long long sm;   int main() {     scanf( %d%d , &n, &x);     for (int i = 0; i < n; ++i) scanf( %d , &v), sm += v;     printf( %s n , sm + n - 1 == x ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x[100], n, a, b, i, dem = 0;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) scanf( %d , &x[i]);     scanf( %d , &a);     scanf( %d , &b);     for (i = a - 1; i != b - 1; i++) dem = dem + x[i];     printf( %d , dem);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SIZE = 500 + 10;   int data[SIZE];   map<int, int> all_nums;   int n;   bool used[SIZE * SIZE];   int gcd(int a, int b) {     if (a % b == 0) return b;     return gcd(b, a % b);   }   void make_data() {     srand(time(0));     int n = 5;     int data[SIZE];     for (int i = 0; i < n; i++) data[i] = (rand() % (10));     FILE* output = fopen( input.txt ,  w );     fprintf(output,  %d n , n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) fprintf(output,  %d  , gcd(data[i], data[j]));     fclose(output);   }   int main() {     cin >> n;     int val;     for (int i = 0; i < n * n; i++) {       cin >> val;       all_nums[val]++;     }     auto iter = all_nums.rbegin();     data[n - 1] = iter->first;     iter->second--;     int curtop = n - 1;     for (int i = 0; i < n - 1; i++) {       while (all_nums.rbegin()->second == 0) {         all_nums.erase(all_nums.find(all_nums.rbegin()->first));       }       data[curtop - 1] = all_nums.rbegin()->first;       all_nums.rbegin()->second--;       for (int k = curtop; k < n; k++)         all_nums[gcd(data[curtop - 1], data[k])] -= 2;       curtop--;     }     for (int i = 0; i < n; i++) cout << data[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};   const int N = 1e6 + 10;   const int mod = 1e9 + 7;   const double pi = acos(-1);   const double eps = 1e-8;   const long long INF = 2e10;   template <class T>   void _print(T arg) {     cout << arg <<    ;   }   template <class... Args>   void log(Args... args) {     int arr[] = {(_print(args), 0)...};     cout << endl;   }   long long a[N], b[N];   int n, m, k;   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 0; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     for (int i = 0; i < n; ++i) {       a[i + 1] += a[i] / 2;       a[i] %= 2;     }     int pos;     for (int i = 0; i <= n; ++i) {       if (a[i]) {         pos = i;         break;       }     }     int res = 0;     long long tmp = 0;     for (int i = n; i >= 0; --i) {       tmp = tmp * 2 + a[i];       if (abs(tmp) > INF) break;       if (i <= pos) {         long long x = abs(tmp - b[i]);         if (i == n & x == 0) continue;         res += (x <= k);       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int d[200060], cost[200060];   long long int m, tank;   vector<pair<int, int>> temp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int src;     cin >> src >> tank >> m;     d[0] = 0;     cost[0] = 0;     d[m + 1] = src;     cost[m + 1] = 0;     for (int i = 0; i < m; i++) {       pair<int, int> t;       cin >> t.first >> t.second;       temp.push_back(t);     }     sort(temp.begin(), temp.end());     for (int i = 0; i < m; i++) {       d[i + 1] = temp[i].first;       cost[i + 1] = temp[i].second;     }     int current = 0;     long long int fuel = tank;     int toAdd = 1;     auto srt = [](int i, int j) {       pair<int, int> a = make_pair(cost[i], d[i]);       pair<int, int> b = make_pair(cost[j], d[j]);       return a < b;     };     multiset<int, function<bool(int, int)>> stations(srt);     long long int ans = 0;     while (true) {       while (!stations.empty() && d[*stations.begin()] < d[current]) {         stations.erase(stations.begin());       }       while (toAdd <= m + 1 && (d[current] + tank) >= d[toAdd]) {         stations.insert(toAdd);         toAdd++;       }       auto it = stations.begin();       if (it == stations.end()) {         cout << -1;         return 0;       }       int minPricy = *it;       if (cost[minPricy] >= cost[current]) {         long long int fuelNeeded = d[minPricy] - d[current];         ans += max(0ll, (tank - fuel) * cost[current]);         fuel = tank - fuelNeeded;         current = minPricy;         stations.erase(it);       } else {         int check = current + 1;         while (cost[current] <= cost[check]) {           check++;         }         int minPricy = check;         long long int fuelNeeded = d[minPricy] - d[current];         ans += max(0ll, (fuelNeeded - fuel) * cost[current]);         fuel = max(fuel - fuelNeeded, 0ll);         current = minPricy;       }       if (current == m + 1) break;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int solveA(vector<int> a, vector<int> b) {     int n = (int)((a).size());     vector<int> m(n);     for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i;     for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]];     b[0] = a[0];     for (int i = (1); i <= ((n - 1)); i++) b[i] = max(b[i - 1], a[i]);     int res = 0;     for (int i = (0); i <= ((n)-1); i++) res += (a[i] != b[i]);     return res;   }   int solveB(vector<int> a, vector<int> b) {     int res = 0, n = (int)((a).size());     vector<int> used(n + 1, false);     while (a.size() || b.size()) {       if (a.size() && b.size() && a.back() == b.back())         b.pop_back(), a.pop_back();       else if (b.size() && used[b.back()])         b.pop_back();       else if (a.size() && a.back() != b.back()) {         used[a.back()] = true;         a.pop_back();         res++;       }     }     return res;   }   int solve(vector<int> a, vector<int> b) {     int n = (int)((a).size());     vector<int> m(n);     for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i;     for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]];     for (int i = (0); i <= ((n - 1) - 1); i++)       if (a[i] > a[i + 1]) {         return n - 1 - i;       }     return 0;   }   int main() {     int n = 100;     scanf( %d , &n);     vector<int> a(n), b(n);     for (int i = (0); i <= ((n)-1); i++) scanf( %d , &a[i]), a[i]--;     for (int i = (0); i <= ((n)-1); i++) scanf( %d , &b[i]), b[i]--;     cout << solve(a, b) << endl;     return 0;   }