#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=2000000000000000000; ll mod=998244353; ll op(ll a,ll b){ return a+b; } ll e(){ return 0; } int main(){ ll n; cin >> n; vectora(n),b(n); for (ll i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (ll i = 0; i < n; i++) { cin >> b[i]; b[i]--; } vectorbb(n); for (ll i = 0; i < n; i++) { bb[b[i]]=i; } for (ll i = 0; i < n; i++) { a[i]=bb[a[i]]; b[i]=i; } vectorc(n,0); segtreeseg(c); ll ans=0; for (ll i = 0; i < n; i++) { ans+=seg.prod(a[i],n); seg.set(a[i],1); } cout << ans << endl; }