#include using namespace std; #define repd(i,a,b) for (ll i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; typedef pair P; typedef vector vec; using Graph = vector>; const long long INF = 1LL<<60; const long long MOD = 1000000007; template struct BIT { private: vector array; const int n; public: BIT(int _n) :array(_n + 1, 0), n(_n) {}; //1番目からi番目までの累積和 T sum(int i) { T s = 0; while (i > 0) { s += array[i]; i -= i & -i;//LSB減算 } return s; } //[i,j]の要素の和 T sum(int i, int j) { T ret_i = sum(i - 1); T ret_j = sum(j); return ret_j - ret_i; } //i番目に要素xを追加する void add(int i, T x) { while (i <= n) { array[i] += x; i += i & -i;//LSB加算 } } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin>>n; vec a(n+1),b(n); rep(i,n){ ll x;cin>>x; a[x]=i; } rep(i,n)cin>>b[i]; vec A(n); rep(i,n){ A[a[b[i]]]=i+1; } ll ans=0; BIT bit(n); rep(i,n){ ans+=bit.sum(A[i],n); bit.add(A[i],1); } cout<