#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include //#include //using namespace atcoder; using namespace std; using i32 = int_fast32_t; using i64 = int_fast64_t; using usize = size_t; using u32 = uint_fast32_t; using u64 = uint_fast64_t; template using vec = vector; #define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using P = pair; void solve(){ } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); u64 n; cin >> n; vec a(n),b(n); vec id(n); rep(i,n){ cin >> a[i]; a[i]--; id[a[i]] = i; } rep(i,n){ cin >> b[i]; b[i]--; } u64 ans = 0; rep(i,n){ u64 now = id[b[i]]; while(a[i] != b[i]){ ans++; swap(a[now],a[now - 1]); now--; id[a[now + 1]] = now + 1; } } cout << ans << endl; }