//#include #include using namespace std; typedef long long ll; typedef pair p; const ll INF = 1e9; const ll LINF = ll(1e18); const ll MOD = 1000000007; const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (ll i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout< bit; T b = 1; // 各要素の初期値は 0 fenwick_tree(T num) : bit(num + 1, 0) { n = num; } // a_i += w void add(T i, T w) { for (T x = i; x <= n; x += x & -x) { bit[x] += w; } } ll get(T i) { ll s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } // [1, i] の和を計算. T sum(T i) { T ret = 0; for (T x = i; x > 0; x -= x & -x) { ret += bit[x]; } return ret; } // [left+1, right] の和を計算. T sum(T left, T right) { return sum(right) - sum(left); } ll get_index(ll x) { //something like lower_bound(all(sum), a). O(logn) x--; while (b * 2 <= n) b *= 2; ll r = b; ll res = 0; while (r > 0) { if ((r | res) <= n) { ll rv = bit[r | res]; if (x >= rv) { x -= rv; res += r; } } r >>= 1; } return res + 1; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; vectora(n),b(n); rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; vector ind(n); rep(i,n){ a[i]--; b[i]--; ind[b[i]]=i; } //debug(ind); rep(i,n){ a[i]=ind[a[i]]+1; } fenwick_tree ft(n+1); //debug(a); ll ans=0; rep(i,n){ ft.add(a[i], 1); ans+=i+1-ft.sum(a[i]); //cout<