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

int main() {
	int n;
	cin >> n;
	map<long long, long long> x;
	vector<long long> y(n);
	map<long long, long long> z;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		x[t]++;
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		z[t]++;
	}
	long long ans = 0;
	for (pair<long long, long long> a : z) {
		ans += a.second * x[y[a.first-1]];
	}
	cout << ans << endl;
}