#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	map<int,vector<int>> y;
	map<int,int> z;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		y[t].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		z[t]++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int jelo = z[i];
		vector<int> scenarija = y[x[i]];
		for (int j : scenarija)
			ans += z[j+1];
	}
	cout << ans << endl;
}