using System;
namespace Zad1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] jela = new long[n];
            long[] recept = new long[n];
            long[] tekst = new long[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] = long.Parse(jelos[i]);
                recept[i] = long.Parse(recepts[i]);
                tekst[i] = long.Parse(teksts[i]);
            }
            long brojac=0,brojac1=0;
            for (int i = 0; i < n; i++)
            {
                if (i >= 2 && jela[i] == jela[i]-1)
                { brojac += brojac1;brojac1 = 0;continue; }
                brojac1 = 0;
                for (int j = 0; j < n; j++)
                {
                    if (jela[i] == recept[j])
                    {
                        for (int k = 0; k < n; k++)
                        {
                            if (j == tekst[k]-1) brojac1++;
                        }
                    }
                }
                brojac += brojac1;
            }
            Console.WriteLine(brojac);

        }
    }
}