#include #define rep(i, n) for(int i=0; i<(int)(n); i++) using namespace std; using ll = long long; using P = pair; int main(){ int n; cin >> n; vector a(n), b(n); rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; // rep(i,n) cout << a[i] << " "; // // cout << endl; // rep(i,n) cout << b[i] << " "; // cout << endl; int ans = 0, id = 0; while(a != b){ int s; rep(i,n){ if(a[id] == b[i] && i != id){ ans += abs(id - i); s = b[i]; rep(id,i+1) b[id+1] = b[id]; b[id] = s; id++; }else{ id++; } } } cout << ans << endl; return 0; }