namespace Zad1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] jela = new int[n];
            int[] recept = new int[n];
            int[] tekst = new int[n];
            string[] jelos = Console.ReadLine().Split();
            string[] recepts = Console.ReadLine().Split();
            string[] teksts = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                jela[i] = int.Parse(jelos[i]);
                recept[i] = int.Parse(recepts[i]);
                tekst[i] = int.Parse(teksts[i]);
            }
            int brojac=0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (jela[i] == recept[j])
                    {
                        for (int k = 0; k < n; k++)
                        {
                            if (j == tekst[k]-1) brojac++;
                        }
                    }
                }
            }
            Console.WriteLine(brojac);

        }
    }
}