using System;
using System.Collections.Generic;
namespace ConsoleApp2
{
    internal class Program
    {   
        static void Main(string[] args)
        {
            Dictionary<int, int> jelo1 = new Dictionary<int, int>();
            int brojac = 0;
            int n = int.Parse(Console.ReadLine());
            string[] unos = Console.ReadLine().Split(' ');
            List<int> jelo = new List<int>();
            List<int> recept = new List<int>();
            List<int> scenario = new List<int>();
            Dictionary<int, int> scen1 = new Dictionary<int, int>();

            jelo1.Add(Convert.ToInt32(unos[0]), 1);
            for (int i = 1; i < n; i++)
            {
                if (jelo1.ContainsKey(Convert.ToInt32(unos[i])))
                {
                    jelo1[Convert.ToInt32(unos[i])] += 1;
                }
                else
                {
                    jelo1.Add(Convert.ToInt32(unos[i]), 1);
                }
            }
                        unos = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                recept.Add(Convert.ToInt32(unos[i]));
            }

                        unos = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {   
                scenario.Add(Convert.ToInt32(unos[i]));
                if (scen1.ContainsKey(Convert.ToInt32(unos[i])))
                {
                    scen1[Convert.ToInt32(unos[i])] += 1;
                }
                else
                {
                    scen1.Add(Convert.ToInt32(unos[i]), 1);
                }
            }

            foreach (KeyValuePair<int, int> par in jelo1)
            {
                int sekundarniBrojac = 0;
                if(recept.Contains(par.Key))
                {
                    for(int i = 0; i < n; i++)
                    {
                        if (recept[i] == par.Key)
                        {
                            if(scen1.ContainsKey(i+1))
                            {
                                sekundarniBrojac += scen1[i + 1];
                            }
                        }
                        brojac += sekundarniBrojac * par.Value;
                        sekundarniBrojac = 0;
                    }
                }
                else { continue; }
            }
            Console.WriteLine(brojac);
        }
    }
}