#include <iostream>
//#include <fstream>
//#include <iomanip>
//#include <cmath>
#include <algorithm>
//#include <string>
#include <vector>
#include <utility>
#include <map>
//#include <ctime>
//#include <cctype>
//#include <cstdlib>
//#include <limits>
//#include <numeric>
//#include <mycpp.h>

using namespace std;

typedef unsigned long long ull;

int main()
{
	std::ios_base::sync_with_stdio(false);
	ull n, in;
	cin >> n;
	map<ull, ull> X;// = new map<ull, ull>();
	map<ull, ull> Y;// = new map<ull, ull>();
	ull y[n];
	vector<ull> x;
	map<ull, ull>::iterator p;
	for(int i = 0; i < n; i++) {
		cin >> in;
		p = X.find(in);
		if(p == X.end()) {
			X.insert(pair<ull, ull>(in, 1));
			x.push_back(in);
		}
		else 
			X.at(in)++;
	}
	for(int i = 0; i < n; i++) {
		cin >> in;
		y[i] = in;
		p = Y.find(in);
		if(p == Y.end())
			Y.insert(pair<ull, ull>(in, 0));
	}
	for(int i = 0; i < n; i++) {
		cin >> in;
		Y.at(y[in-1])++;
	}
	ull res = 0;
	for(int i = 0; i < x.size(); i++) {
		ull key = x[i];
		//cout << "key: " << key << "\t" << "x: " << X.at(key) << "\t";
		p = Y.find(key);
		if(p != Y.end()) {
			res += (X.at(key) * Y.at(key));
			//cout << "Y: " << Y.at(key);
		}
		//cout << endl;
	}
	cout << res << endl;
}