import java.util.*;
import java.io.*;
import java.math.*;
public class difficult{
	
	public static void main(String[] args){
		//PrintReader sc = new PrintReader(new BufferedReader(new InputStreamReader(System.in)));
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if (n==0)
				break;
			sc.nextLine();			
			int[] p1 = new int[n];
			int[] p2 = new int[n];
			int[] p3 = new int[n];
			
			for(int o = 0; o < n;o++)
			{
				if (sc.hasNextInt()==false)
					sc.nextLine();
				p1[o]=sc.nextInt();
			}
			
			for(int o = 0; o < n;o++)
			{
				if (sc.hasNextInt()==false)
					sc.nextLine();
				p2[o]=sc.nextInt();
			}
			
			for(int o = 0; o < n;o++)
			{
				if (sc.hasNextInt()==false)
					sc.nextLine();
				p3[o]=sc.nextInt();
			}

			int[] pocty = new int[n];
			
			BigInteger vysledek = BigInteger.ZERO;
			 
			for(int i=0;i<n;i++)
			{
				for(int a=index(p1,p1[i])+1;a<n;a++)
					pocty[p1[a]-1]++;
				for(int b=index(p2,p1[i])+1;b<n;b++)
					pocty[p1[b]-1]++;
				for(int c=index(p3,p1[i])+1;c<n;c++)
					pocty[p1[c]-1]++;
							
				
				int t = 0;

				for(int l=0;l<n;l++)
				{
					if (pocty[l]==3)
						t++;
					pocty[l]=0;
				}	
					
				
				
				vysledek = vysledek.add(BigInteger.valueOf(t));
			}			
			System.out.println(""+vysledek);	
		}
	}
		
		static int index(int[] pole, int num)
		{
			for(int o = 0; o < pole.length;o++)
				if(pole[o]==num)
					return o;
			return -1;
		}
	
	}
