#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; long long inversion_number(vector &A){ int N = A.size(); vector B = A; sort(B.begin(), B.end()); map mp; for (int i = 0; i < N; i++) mp[B[i]] = i + 1; for (int i = 0; i < N; i++) A[i] = mp[A[i]]; long long ans = 0; vector BIT(N + 1, 0); for (int i = 0; i < N; i++){ ans += i; int j; j = A[i]; while (j > 0){ ans -= BIT[j]; j -= j & -j; } j = A[i]; while (j <= N){ BIT[j]++; j += j & -j; } } return ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector a(n), b(n); rep(i,n) cin >> a[i], a[i]--; rep(i,n) cin >> b[i], b[i]--; vector bpos(n); rep(i,n) bpos[b[i]] = i; rep(i,n) a[i] = bpos[a[i]]; cout << inversion_number(a) << endl; }