#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for (int i = 0; i < (ll)(n); i++) #define req(i,n) for(int i = 1;i <= n; i++) #define rrep(i,n) for(ll i = n-1;i >= 0;i--) #define ALL(obj) begin(obj), end(obj) #define RALL(a) rbegin(a),rend(a) typedef long long ll; typedef long double ld; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = 0x3fffffff; const ll INF = 1e18; class BIT { public: int n; vector a; BIT(int n) :n(n), a(n + 1, 0) {} void add(int i, ll x) { i++; if (i == 0)return; for (int j = i; j <= n; j += (j & -j)) a[j] += x; }ll sum(int i) { i++; ll sum = 0; if (i == 0)return sum; for (int j = i; j > 0; j -= (j & -j)) sum += a[j]; return sum; } }; int main() { int n, m; cin >> n; vector a(n), A(n + 1), b(n), B(n + 1); rep(i, n) { cin >> a[i]; }vector> p; rep(i, n) { cin >> b[i]; B[b[i]] = i + 1; } rep(i, n) p.push_back({ B[a[i]],i + 1 }); sort(RALL(p)); BIT bit(n + 1); ll ans = 0; for (pair i : p) { ans += bit.sum(i.second); bit.add(i.second, 1); }cout << ans << endl; }