#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
using namespace std;
ll mode = 1e9 + 7;
const ll maxn = 2*1e5 + 5;
const ll inf = 1e18;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.F << ", " << a.S << ")"; }
template <class A> ostream& operator << (ostream& out, const vector<A> &v) { 
out << "["; for (int i=0;i<v.size();i++) { if(i) out << ", "; out << v[i]; } return out << "]"; }

void solve(){
	
	ll n;
	cin>>n;
	map<int,vector<int>> b;
	map<int,int> ma, mb, mc;
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		ma[x]++;
	}
	for (int i=1;i<=n;i++){
		ll x;
		cin>>x;
		b[x].pb(i);
		mb[x]++;
	}
	for (int i=1;i<=n;i++){
		ll x;
		cin>>x;
		mc[x]++;
	}
	
	ll ans = 0;
	for (int i=1;i<=n;i++){
		if (mb.count(i)==0) continue;
		vector<int> bb = b[i];
		for (auto j:bb){
			ans = ans + ma[i]*mc[j];
		}
	}
	cout<<ans<<endl;
	
}


int main(){ 
    
    #ifndef ONLINE_JUDGE
//		freopen("input.txt", "r", stdin);
//		freopen("output.txt", "w", stdout);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	ll test_case = 1;
	//cin>>test_case;
	for (int i=1;i<=test_case;i++){
		solve();
	}
	
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

int main()
{
 int n,x;
 cin >> n;
 int arr1[n+2]= {0};
 memset(arr1,0,sizeof(arr1));

 for(int i=1; i<=n; i++)
 {
   cin>>x;
   arr1[x]++;
 }

 int arr2[n+1];
 for(int j=1;j<=n; j++)
 {
   cin >> arr2[j];
 }

 unsigned long long int cnt=0;
 while(n--)
 {
   cin >> x;
   int k=arr2[x];
   cnt=cnt+arr1[k];
 }
 cout<<cnt<<endl;


}

