#include <bits/stdc++.h>
using namespace std;
int n, sol, z; int x[100096]; int y[100096]; map <int, int> m; bool zisti = true;
int main()
{
  scanf("%d", &n);
  for(int i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  for(int i = 1; i <= n; i++)
    scanf("%d", &y[i]);
  for(int i = 1; i <= n; i++)
  {
    scanf("%d", &z), m[z]++;
  }
  if(m.size() != 1)
    zisti = false;
  if(zisti == false)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= n; j++)
        if(y[j] == x[i])
          sol += m[j];
    }
  }
  else
  {
    for(int i = 1; i <= n; i++)
      if(x[i] == y[z])
        sol += n;
  }
  printf("%d\n", sol);


  return 0;
}