#include <stdio.h>
void unos(unsigned int n,unsigned int a[])
{
	unsigned int i;
	for(i=0;i<n;i++)
		scanf("%u",&a[i]);
}
main()
{
	unsigned int n,i,j,k,x[100000],y[100000],z[100000];
	int b=0,ind=0;
	scanf("%u",&n);
	
	unos(n,x);
	unos(n,y);
	unos(n,z);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			if(x[i]==y[z[j]-1])
				b++;
	
	printf("%u",b);
}