#include <iostream>
#include <cstdio>

using namespace std;

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

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

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

    return ans;
}

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

int main() {
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    #endif // ONLINE_JUDGE
    //cin.sync_with_stdio(false);
    scanf("%d\n", &N);

    for(int i = 1; i <= N; ++i) {
        scanf("%d", &x);
        freq[x] = i;
    }

    long long ans = 0;
    for(int i = 1; i <= N; ++i) {
        //cerr << i << '\n';
        scanf("%d", &x);

        x = freq[x];

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

    cout << ans << '\n';

    return 0;
}