#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    ll x[100001]={};
    for(ll i=0;i<n;i++){
        ll a;
        cin>>a;
        x[a]++;
    }
    ll y[n+1],z[n],yz[100001]={};
    for(ll i=1;i<n+1;i++){
        cin>>y[i];
    }
    for(ll i=0;i<n;i++){
            ll b;
            cin>>b;
            yz[y[b]]++;
    }
    ll r=0;
    for(ll i=1;i<100001;i++)
        r=r+x[i]*yz[i];
    cout<<r;
}