//doit4von
//LLJW
//999
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const long long mod=pow(10,9)+7;
typedef long long ll;
#define pb push_back
#define vi vector<int>
#define sz(x) (int)(x).size()
void google(int tc)
{
    cout<<"Case #"<<tc<<": ";
}
ll convert(string z)
{
      ll ans=0;
      int count=0;
      for(int i=z.length()-1;i>=0;i--)
      {
            ans=ans+(z[i]-'0')*pow(10,count);
            count++;
      }
      return ans;
}
bool palindrome(const string &s) {
    int n = s.length();
    for(int i = 0; i < n; i++) {
        if(s[i] != s[n - i - 1]) return false;
    }
    return true;
}
bool primecheck(long long int z)
{
      for(long long int i=2;i*i<=z;i++)
      {
            if(z%i==0)
            return false;
      }
      return true;
}
string boolean (int y)
{
      string ans="";
      while(y>0)
      {
            ans=(char)('0'+y%2)+ans;
            y=y/2;
      }
      return ans;
}
ll rem(ll x)
{
      ll ans=0;
      while(x>0)
      {
            if(x%10)
            ans=ans*10+x%10;
            x=x/10;
      }
      return ans;
}
/*ll total=0;
ll no=0;
bool visited[N];
vector  <int> v[N];
int n;
void dfs(int curr ,int level)// curr=current node level=number of nodes travelled to reach there
{
      if(visited[curr]==true)
      return;
      visited[curr]=true;
      for(auto y : v[curr])
      dfs(y,level+1);
      if(v[curr].size()==1 && curr!=1)
      {
            total=total+level;
            no++;
      }
}*/
int SieveOfEratosthenes(int n)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for (int p = 2; p * p <= n; p++)
    {
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
            prime[i] = false;
        }
    }
    int ans=0;
    for (int p = 2; p <= n; p++)
        ans+=prime[p];
    return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
map <int,int> a;
for(int i=0;i<n;i++)
{
    int ex;
    cin>>ex;
    a[ex]++;
}
int b[n+2];
for(int i=1;i<=n;i++)
cin>>b[i];
ll ans=0;
for(int j=0;j<n;j++)
{
    int ex;
    cin>>ex;
    ans=ans+a[b[ex]];
}
cout<<ans;
}










/* Vineeth Kada */

#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define rrep(i,a,b) for(int i=a; i>=b; i--)
#define inf(dtype) numeric_limits<dtype>::max()

int Solve(){
    int n; cin >> n;
    int a[n+1], b[n+1], c[n+1];
    rep(i, 1, n) cin>>a[i];
    rep(i, 1, n) cin>>b[i];
    rep(i, 1, n) cin>>c[i];
    map<int, int> hm;
    rep(i, 1, n) hm[c[i]]++;
    int ans[n+1];
    rep(i, 1, n){
        ans[i] = 0;
        
    }
    rep(i, 1, n){
        ans[b[i]] += hm[i];
    }
    int output = 0;
    rep(i, 1, n){
        output += ans[a[i]];
    }
    cout << output << endl;
    return 1;
}

int32_t main(){
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--) Solve();
    return 0;
}
