#include <bits/stdc++.h>

#define maxn 10000

#define unos(a, n)for(int i = 1;i<=n;i++)cin>>a[i];

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t, resenje = 0, n, xi[maxn], yi[maxn];
    set<int> ts;
    vector<int> zi(maxn, 0);
    cin >> n;
    unos(xi, n);
    unos(yi, n);
    for(int i = 1; i <= n; i++){
        cin >> t;
        ts.insert(t);
        zi[t]++;
    }
    for(int i = 1; i <= n; i++){
        for(int j : ts){
            if(xi[i] == yi[j]){
                resenje += zi[j];
            }
        }
    }
    cout << resenje;
}