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

int main()
{
    int n;
    cin >> n;
    int x[n+1], y[n+1], z[n+1];
    
    for (int i = 1; i <= n; i++)
    {
        cin >> x[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> y[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> z[i];
    }

    ll c = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++) {
            c+= x[i] == y[z[j]];
        }
    }

    cout << c << "\n";
    
    
    return 0;
}