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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll n, ind;
    map<int, int> mp;
    cin >> n;
    ll x[n], y[n], z[n];

    for(int i=0;i<n;++i)
        cin >> x[i];

    for(int i=0;i<n;++i)
        cin >> y[i];

    for(int i=0;i<n;++i)
        cin >> z[i];

    for(int i=0;i<n;++i)
    {
        ind = z[i] - 1;
        mp[y[ind]]++;
    }

    ll ans=0;
    for(int i=0;i<n;++i)
    {
        if(mp[x[i]])
        {
            ans += mp[x[i]];
        }
    }
    cout << ans;







}