#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],q[n+1];
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=1;i<=n;i++)cin>>b[i];
    map<ll,vector<ll>>m;
    map<ll,ll>rez;
    for(ll i=1;i<=n;i++)m[b[i]].pb(i);
    for(ll i=1;i<=n;i++){
        cin>>q[i];
        rez[q[i]]++;
    }
    map<ll,ll>pos;
    for(int i=1;i<=n;i++)pos[b[i]]=1;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(!pos[a[i]])continue;
       // cout<<a[i]<<" :::";
        for(auto it:m[a[i]]){
            //cout<<it<<" ";
            ans+=rez[it];
        }
        //cout<<endl;
    }
    cout<<ans;
}