#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; const ll MOD = 1000000007; const ll INF = 1e18; #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() int main(){ int n; cin >> n; VI a(n), p(n+1); REP(i,n) cin >> a[i]; int b; REP(i,n){ cin >> b; p[b]=i; } REP(i,n) a[i]=p[a[i]]; ll ans=0; VI c; REP(i,n){ auto itr=lower_bound(ALL(c),a[i]); ans+=c.size()-(itr-c.begin()); c.insert(itr,a[i]); } cout << ans << endl; return 0; }