//clear adj and visited vector declared globally after each test case
//check for long long overflow  
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14  
#include <bits/stdc++.h>    
#include <ext/pb_ds/assoc_container.hpp>  
#define int long long 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n+1], b[n+1], c[n+1];
    rep(i,1,n+1)
    cin>>a[i];
    rep(i,1,n+1)
    cin>>b[i];
    int co[n+1];
    fill(co, 0);
    rep(i,1,n+1)
    {
        cin>>c[i];
        c[i]=b[c[i]];
        co[c[i]]++;
    }
    int ans=0;
    rep(i,1,n+1)
    ans+=co[a[i]];
    cout<<ans;
}
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) a.begin(), a.end()
#define sz(x) x.size()
#define yn(p) cout << (p?"Yes":"No") << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;
// #include <atcoder/all>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace atcoder;
// using lll = boost::multiprecision::cpp_int;
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;
const int INF = 1000000000;
const int MOD = 1000000007;
const ll llINF = 1000000000000000000;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
  }
  vector<ll> x(100001, 0), y(100001, 0);
  for (int i = 0; i < n; ++i) {
    ++x[a[i]];
    ++y[b[c[i]-1]];
  }
  ll ans = 0;
  for (int i = 0; i < 100001; ++i) {
    ans += x[i] * y[i];
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
  return 0;
}