#include <iostream>

using namespace std;

int main()
{
	int n, br = 0;
	cin >> n;
	
	int x[n], y[n], z[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];	
	
	int index;
		
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (x[i] == y[j])
			{
				index = j;
				for (int k = 1; k <= n; k++){
					if (z[k] == index)
					br++;
				}
			}
		}			
	} 
	
	cout << br;
	
	return 0;
}