#include <bits/stdc++.h>
#define ll long long int
#define vll vector<long long int>
using namespace std;
ll MOD = 1e9 + 7;

void solver(){
	ll n;
	cin>>n;
	vll a(n),b(n),c(n);
	map<ll,ll> mp;
	for(ll i=0;i<n;i++)cin>>a[i];
	
	for(ll i=0;i<n;i++)cin>>b[i];
	
	for(ll i=0;i<n;i++)cin>>c[i];

	for(ll i=0;i<n;i++){
		mp[b[c[i]-1]]++;
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
		ans+=mp[a[i]];
	}
	cout<<ans<<"\n";
}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	ll t = 1;
	//cin>>t;
	while (t--){
		solver();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> PI;
typedef vector<int> VI;
typedef vector<PI> VPI;

template<class T> bool tmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool tmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define F first
#define S second
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int _n(b),i(a);i<_n;i++) 
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define TRAV(a,x) for (auto& a : x)

void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

const int MX = 100005;
int cnt[MX], b[MX], c[MX];
int n;

LL solve() {
    LL r = 0;
    REP(j, n) r += cnt[b[c[j+1]]];
    return r; 
}

int main() {
    setIO();
    cin>>n;
    REP(i, n) {
        int x; cin >> x;
        cnt[x]++;
    }
    REP(i, n) cin >> b[i+1];
    REP(i, n) cin >> c[i+1];
    cout<<solve()<<"\n";
    
    return 0;
}
