#include <iostream>

using namespace std;

int nadjiindex(int niz1[], int niz2[], int niz3[], int n) {
	int brojac = 0;
	for (int x = 0; x<n; x++) {
		for (int y = 0; y<n; y++) {
			if (niz1[x] == niz2[y]) {
				int index = y+1;
				for (int j = 0; j<n; j++) {
					if (niz3[j] == index) brojac++; 
				}
			}
		}
	}
	cout << brojac << '\n';
	return brojac;
}

int main() {
	
	int n, brojac = 0, index;
	cin >> n;
	int jelo[n];
	int recept[n];
	int scenario[n];
	
	for(int i = 0; i<n; i++)
		cin >> jelo[i];
	for(int i = 0; i<n; i++)
		cin >> recept[i];
	for(int i = 0; i<n; i++)
		cin >> scenario[i];
	index = nadjiindex(jelo, recept, scenario, n);	
		
	
return 0;
}