#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main() {
	
	int n;
	cin >> n;
	
	vector<int> x(n);
	vector<int> y(n);
	vector<int> z(n);
	
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> z[i];
	}
	
	int tx = 0;
	int tz = 0;
	int rez = 0;
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if(x[j] == y[i]) {
				tx++;
			}
			if (z[j] == i + 1) {
				tz++;
			}
		}
		rez += tx * tz;
		tx = 0;
		tz = 0;
	}
	
	cout << rez;
	
	return 0;
}

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