using System;
class HelloWorld
{

    static void Main() {

        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split();
        var b = Console.ReadLine().Split();
        var c = Console.ReadLine().Split();
        int[] X = new int[n];
        int[] Y = new int[n];
        int[] Z = new int[n];
        int i = 0;
        int[] dx = new int[100000];
        for (i=0;i<n;i++)
        {
            X[i] = int.Parse(a[i]);
            Y[i] = int.Parse(b[i]);
            Z[i] = int.Parse(c[i]);
        }
        int count = 0;
        int fcount = 0;

        for (i=0;i<n;i++)
        {
            count = 0;
            if (dx[X[i]] != 0)
            {
                fcount += dx[X[i]];
            }
            else
            {
                for (int z = 0; z < n; z++)
                {
                    if (X[i] == Y[z] && dx[X[i]] == 0)
                    {
                        for (int l = 0; l < n; l++)
                        {
                            if (z + 1 == Z[l])
                            {
                                count++;
                                fcount++;
                            }
                        }
                        break;
                    }
                    else if (X[i] == Y[z])
                    {
                        fcount += dx[X[i]];
                        break;
                    }
                }
            }
            dx[X[i]] += count;
        }   
        Console.WriteLine(fcount);
        
        
    }
}