#include <iostream>

using namespace std;

int compare(const void *a,const void *b)
{
	const int *x= (int*)a;
	const int *y= (int*)b;
	if(*x>*y){return 1;}
	if(*x<*y){return -1;}
	return 0;
}

int bp(int z[],int l,int h,int trazeni)
{
	int m=(l+h)/2;
	if(trazeni==z[l]){return l;}
	if(trazeni==z[m]){return m;}
	if(trazeni==z[h]){return h;}
	if(trazeni>z[m])
	{
		if(m+1==l){return -1;}
		return bp(z,m+1,h,trazeni);
	}
	else{
		if(h==m-1){return -1;}
		return bp(z,l,m-1,trazeni);
	}
}

int main()
{
	int n;
	long long rez=0,prez=0,k=0,najvecaVrednostY=0;
	cin >> n;
	int x[n],y[n],z[n],f,provera;
	for(int i=0;i<n;i++){cin >> x[i];}
	for(int i=0;i<n;i++){cin >> y[i];if(y[i]>najvecaVrednostY)najvecaVrednostY=y[i];}
	for(int i=0;i<n;i++){cin >> z[i];}
	qsort(x,n,sizeof(int),compare);
	qsort(z,n,sizeof(int),compare);
	for(int j=0;j<n;j++)
	{
		//cout << "x[" << 0 << "] = " << x[0] << " , " << "y[" << j << "] = " << y[j] << endl;
		///if(najvecaVrednostY<x[0]){cout << rez << endl;return 0;}
		if(x[0]==y[j])
		{
			j++;
					f=bp(z,0,n-1,j);
					int h=f+1;
					provera=z[h];
					while(z[h]==provera){prez++;h++;}
					h=f;
					while(z[h]==provera){prez++;h--;}
					j--;
		}
	}
	rez+=prez;		
	for(int i=1;i<n;i++)
	{
		if(x[i]>najvecaVrednostY){cout << rez << endl;return 0;}
		if(x[i]==x[i-1]){rez+=prez;}
		else{
			prez=0;
			for(int j=0;j<n;j++)
			{
				//cout << "x[" << i << "] = " << x[i] << " , " << "y[" << j << "] = " << y[j] << endl;
				if(x[i]==y[j])
				{
					j++;
					f=bp(z,0,n-1,j);
					int h=f+1;
					provera=z[h];
					while(z[h]==provera){prez++;h++;}
					h=f;
					while(z[h]==provera){prez++;h--;}
					j--;
				}
			}
			rez+=prez;
		}
	}
	cout << rez << endl;
	return 0;
}