#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int32_t main(){
    fast
    int t=1;
    // cin>>t;
    while(t--){
        int n;cin>>n;int a[n], b[n], c[n];rep(i, n)cin>>a[i];rep(i, n)cin>>b[i];rep(i, n)cin>>c[i];
        map<int, int>m1, m2;
        set<int>s;
        rep(i, n)m1[a[i]]++, s.insert(a[i]);
        rep(i, n)m2[b[c[i]-1]]++;
        int ans=0;
        for(auto i:s){
            ans+=(m1[i]* m2[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N), BC(N), count(N+1);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) cin >> B[i];
    for (int i=0; i<N; i++) cin >> C[i];

    for (int j=0; j<N; j++) {
        BC[j] = B[C[j]-1];
        count[BC[j]]++;
    }
    
    long long answer = 0;
    for (int a : A) {
        answer += count[a];
    }
    cout << answer << endl;
    return 0;
}