#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, br=0;
    cin >> n;
    int 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];

    int counter[n];
    memset(counter, 0, sizeof(counter));

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

     for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (x[i] == y[j])
                br += counter[j];
        }
    }

    cout << br;

    return 0;
}