using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int[] X;
           
            X = new int[N];
            int[] Y;

            Y = new int[N];
            int[] Z;

            Z = new int[N];

            string []XX = Console.ReadLine().Split();
            for (int j=0; j < N; j++ )
            {
                X[j] =Convert.ToInt32( XX[j]);
            }

            string[] YY = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                Y[i] = Convert.ToInt32(YY[i]);
            }

            string[] ZZ = Console.ReadLine().Split();
            for (int z = 0; z < N; z++)
            {
                Z[z] = Convert.ToInt32(ZZ[z]);
            }


            int brojac = 0;
            for (int k = 0; k < N; k++ )
            {
                for(int s =0; s<N;s++)
                {
                    if (X[k] == Y[s])
                    {

                        for (int t = 0; t < N; t++)
                        {
                            if ( Z[t] == s + 1)
                            {
                                brojac++;

                            }

                        }
                    }
                    
                }
            }
            Console.WriteLine(brojac);

               
        }
    }
}