#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long> a(n), b(n), c(n);
    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];
        c[i]--;
    }
    long long bas[100001] = {0};
    for(int i = 0;i < n;i++) bas[a[i]]++;
    long long cnt = 0;
    for(int i = 0;i < n;i++)    cnt += bas[b[c[i]]];
    cout << cnt << endl;

}
// jay swaminarayan //
// UTSAV VASOYA //
#include <iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<cmath>
#include<string.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
// All func 
int fastpower(long a,long b,int n=1000000007){ long res=1; while(b>0){ if((b&1)!=0){ res = (res%n * a%n)%n ;} a = (a%n * a%n)%n; b=b>>1;} return res;}
int checkPrime(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for(int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } int cprime=0; for(int p=2; p<=n; p++) if(prime[p]) cprime++; return cprime;}
int gcd(int a, int b){  int c = a % b;  while(c != 0)  {    a = b;    b = c;    c = a % b;  }  return b;}
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);


int32_t main(){
fast
// just chill chill just chill
    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>mp1;
    map<int,int>mp2;
    vector<int>v;
    rep(i,n){
        mp1[a[i]]++;
        mp2[b[i]]++;
        v.push_back(b[i]);
    }
    int ans=0;
    for(int i=0; i<n; i++){
        int m = b[c[i]-1];
        int p = mp1[m];
            int count = p;
            ans+=count;
        // mp1[m]=0;
        // mp2[m]=0;
    }
    cout << ans;

return 0;
}
