/*
    This too shall pass
*/
#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define pii pair <int, int>
#define INF 2e18
#define int long long

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in19.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int T=1;
    // cin >> T;
    
    for(int tt = 1; tt <= T; tt++){
        // cout << "Case #" << tt << ": ";
        int n; cin >> n;
        int a[n+1];
        for(int i = 1; i <= n; i++) cin >> a[i];
        int b[n+1];
        for(int i = 1; i <= n; i++) cin >> b[i];  
        int c[n+1];
        for(int i = 1; i <= n; i++) cin >> c[i];

        map<int, int> m;
        for(int i = 1; i <= n; i++){
            m[b[c[i]]]++;
        }

        int ans = 0;
        for(int i = 1; i <= n; i++){
            ans += m[a[i]];
        }
        cout << ans;
        cout << '\n';
    }
    return 0;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//optimal subsequences-2 technocup round-3 2020
using namespace std;
using namespace __gnu_pbds;
const int N=2e5+10;
//#define d double
#define F first
#define S second
#define ll long long int
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(6)
const int M=1e9+7;
//const int M=998244353;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
//#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//int MOD=998244353;
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

//ll d1=304933,d2=4395853;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r" , stdin);
//freopen("output.txt", "w", stdout);
//#endif

ll power(ll a,ll b)
{
    ll res=1;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

void solve()
{
    int n;cin>>n;

    int a[n+1],b[n+1],c[n+1];

    f(n)cin>>a[i+1];
    f(n)cin>>b[i+1];
    f(n)cin>>c[i+1];

    map<int,ll>m;

    f(n)m[a[i+1]]++;

    ll ans=0;

    f(n)
    {
        int id=c[i+1];
        int x=b[id];
        ans+=m[x];
    }

    cout<<ans;
}

int main()
{
    FastIO;

    int t=1;
    //cin>>t;

	for(int i=1;i<=t;i++)
    {
        //if(i!=t)cout<<endl;
        solve();
    }
	return 0;
}
