#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 3000009
using namespace std;
inline ll read(){
	ll s;
	scanf("%lld",&s);
	return s;
} 
long long a[N],b[N],c[N],p[N];
int main(){
	int n=read();
	for(int i=1;i<=n;++i){
		p[read()]++;
	} 
	for(int i=1;i<=n;++i){
		b[i]=read(); 
	}
	for(int i=1;i<=n;++i){
		c[i]=read();
	}
	for(int i=1;i<=n;++i){
		a[b[c[i]]]++;
	}
	long long ans=0;
	for(int i=1;i<=n;++i){
		ans+=a[i]*p[i];
	}
	cout<<ans;
	return 0;
} 
/*
100
1 1 1 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 1 1 2 2 2 1 1 1 2 1 2 1 2 2 2 1 1 1 1 1 1 1 2 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 2 2 2 1 1 2 2 2 1 2 1 1 1 1 2 1 2 1 1 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1
*/
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> a(n),b(n),c(n);
  for(auto& i:a) cin>>i;
  for(auto& i:b) cin>>i;
  for(auto& i:c) cin>>i;
  sort(a.begin(),a.end());
  long long ans=0;
  for(int i=0; i<n; ++i){
    int x=(int)(upper_bound(a.begin(),a.end(),b[c[i]-1])-a.begin());
    if(a[x-1]!=b[c[i]-1]) continue;
    ans+=(x-(int)(lower_bound(a.begin(),a.end(),b[c[i]-1])-a.begin()));
  }
  cout<<ans<<endl;
  return 0;
}