#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
#include<set>
typedef long long ll;
using namespace std;
#define rep(x, y)   for (ll i = x; i < y; i ++)
#define repi(x, y)  for (ll i = x; i > y; i --)
#define si(x) ll x;cin>>x
ll arr[200005];
vector<ll> brr[100005];
ll crr[100005];
ll drr[100005];
set<int, greater<int> > num;
set<int, greater<int> >::iterator numitr;

int main()
{
    ll test = 1;
    // cin>>test;
    for(ll z=0;z<test;z++)
    {
        si(n);
        for(ll i=0;i<=n;i++)
        {
            crr[i] = 0;
            drr[i] = -1;
        }
        for(ll i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(ll i=0;i<n;i++)
        {
            si(a);
            brr[a].push_back(i+1);
        }
        for(ll i=0;i<n;i++)
        {
            ll a;
            cin>>a;
            crr[a]++;
        }
        ll counter =0;
        for(ll i=0;i<n;i++)
        {
            if(drr[arr[i]] == -1)
            {
                ll prevcounter = counter;
                for(ll j = 0;j<brr[arr[i]].size();j++)
                {
                    counter += crr[brr[arr[i]][j]];
                }
                drr[arr[i]] = counter - prevcounter;
            }
            else
            {
                counter += drr[arr[i]];
            }
        }
        cout<<counter<<endl;

    }
    
}

#include <algorithm>
#include <vector>

#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;

int main(){

    //int a, b, c;
    int n;

    cin >> n;

    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    int t;

    for(int i=0;i<n;i++){
        cin >> t;
        a[i]=t-1;
    }
    for(int j=0;j<n;j++){
        cin >> t;
        b[j]=t-1;
    }
    for(int k=0;k<n;k++){
        cin >> t;
        c[k]=t-1;
    }

    vector<int> count(n);
    for (int j = 0; j < n; ++j) {
        count[b[c[j]]] += 1;
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += count[a[i]];
    }
    cout << ans << '\n';


    return 0;
}