#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, br=0;
    cin >> n;
    int x[n], y[n], z[n], counterz[n], countery[n];
    memset(counterz, 0, sizeof(counterz));
    memset(countery, 0, sizeof(countery));
    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++){
        counterz[z[i]-1]++;
    }

    for (int i = 0; i < n; i++) {
        countery[y[i]-1]+=counterz[i];
    }

     for (int i = 0; i < n; i++) {
        br += countery[x[i]-1];
    }

    cout << br;

    return 0;
}