#include <iostream>
#include <cstdio>

using namespace std;

int aib[50003];
int x, freq[50004];

int query(int pos) {
    int ans = 0;

    for(;pos;pos -= pos & (-pos)) {
        ans += aib[pos];
    }

    return ans;
}

void update(int pos) {
    for(;pos <= 50000; pos += pos & (-pos)) {
        aib[pos]++;
    }
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE
    cin.sync_with_stdio(false);
    int N;
    cin >> N;

    for(int i = 1; i <= N; ++i) {
        cin >> x;
        freq[x] = i;
    }

    long long ans = 0;
    for(int i = 1; i <= N; ++i) {
        cin >> x;

        x = freq[x];

        ans += query(x);
        update(x);
    }

    cout << ans << '\n';

    return 0;
}