using System;

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long rez = 0;
            long a = 0;
            long b = 0;
            long b1 = 0;
            long c = 0;

            string s11 = Console.ReadLine();
            string s21 = Console.ReadLine();
            string s31 = Console.ReadLine();

            string[] s1 = s11.Split(" ");
            string[] s2 = s21.Split(" ");
            string[] s3 = s31.Split(" ");

            long[] X = new long[N];
            long[] Y = new long[N];
            long[] Z = new long[N];


            for (long i = 0; i < N; i++)
            {
                X[i] = long.Parse(s1[i]);
                Y[i] = long.Parse(s2[i]);
                Z[i] = long.Parse(s3[i]);
            }
           Array.Sort(X);


            for (int i = 0; i < N; i++)
            {

                a=X[i];
                for (int j = 0; j < N; j++)
                {
                    if (Y[j]==a)
                    {
                        b++;
                        b1 = j+1;
                        for (int o = 0; o < N; o++)
                        {
                            if (Z[o]==b1)
                            {
                                c++;
                            }
                        }
                        rez +=  c;
                        c = 0;
                    }
                }

              
            }
            Console.WriteLine(rez);







        }
    }
}