#include <iostream>

using namespace std;

int main()
{
	int n, br = 0;
	cin >> n;
	
	cin.tie(0);
	int x[n], y[n], z[n], a[3][n];
	
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	
	for (int i = 1; i <= n; i++)
		cin >> y[i];
		
	for (int i = 1; i <= n; i++)
		cin >> z[i];
		
	for (int j = 1; j <= n; j++){
		a[1][j] = y[j];
		a[2][j] = z[j];
	}
	
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (x[i] == a[1][z[j]])
				br++;
		}			
	} 
	
	cout << br;
	
	return 0;
}