#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char** argv) {

/*
4
1 1 4 3
3 1 3 4
1 3 2 2

6
*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a;
    long long rez=0;
	cin>>n;
	vector <int> epizode(n);
	vector <vector<int> > recepti(n+1);
	vector <int> scenariji(n+1);
	for (int i=0;i<n;i++){
		cin>>epizode[i];
	//	cout<<epizode[i]<<endl;
		scenariji[i]=0;
	}
	for (int i=0;i<n;i++){
		cin>>a;
//		cout<<a<<endl;
		recepti[a].push_back(i+1);
//		for (int idot=0;idot<recepti[a].size();idot++) cout<<recepti[a][idot]<<" ";
//		cout<<endl;
	}
	for (int i=0;i<n;i++){
		cin>>a;
		scenariji[a]++;
	}
	for (int i=0;i<n;i++){
//		cout<<i<<endl;
//		cout<<epizode[i]<<endl;
		for (int idot=0;idot<recepti[epizode[i]].size();idot++){
/*			cout<<idot<<endl;
			cout<<i<<" "<<idot<<endl;
			cout<<recepti[epizode[i]][idot]<<endl;
			cout<<scenariji[recepti[epizode[i]][idot]]<<endl;
*/			rez+=scenariji[recepti[epizode[i]][idot]];
//			cout<<idot<<endl;
		}
	}
	cout<<rez;
	

	return 0;
}