/// Author: NemanjaSo2005
/// Date: 26th February 2023
/// Contest: Serbian high school regional contest
/// Anyone can use any part of this code for any purpose after the contest.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N,X[100005],Y[100005],Z[100005],kolZ[100005],kolY[100005];
ll min(ll a,int b){
   if(a<b)
      return a;
   return b;
}
ll min(int a,ll b){
   if(a<b)
      return a;
   return b;
}
ll max(ll a,int b){
   if(a>b)
      return a;
   return b;
}
ll max(int a,ll b){
   if(a>b)
      return a;
   return b;
}
void solve(){
   cin>>N;
   for(int i=1;i<=N;i++)
      cin>>X[i];
   for(int i=1;i<=N;i++)
      cin>>Y[i];
   for(int i=1;i<=N;i++)
      cin>>Z[i];
   for(int i=1;i<=N;i++)
      kolZ[Z[i]]++;
   for(int i=1;i<=N;i++)
      kolY[Y[i]]+=kolZ[i];
   ll res=0;
   for(int i=1;i<=N;i++)
      res+=kolY[X[i]];
   cout<<res<<"\n";
   return;
}
void reset(){}
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int T=1;
   //cin>>T;
   while(T--){
      solve();
      reset();
   }
   return 0;
}