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

int main()
{
    string Nstr;
    int N;
    getline(cin, Nstr);
    stringstream ssoN;
    ssoN << Nstr;
    ssoN >> N;
    vector<int> X,Y,Z;
    string Xstr, Ystr, Zstr, test;
    getline(cin, Xstr);
    getline(cin, Ystr);
    getline(cin, Zstr);
    stringstream ssoX,ssoY,ssoZ;
    int x,y,z;
    ssoX << Xstr;
    ssoY << Ystr;
    ssoZ << Zstr;
    for(int i= 0; i < N; i++){
        ssoX >> x;
        X.push_back(x);
        ssoY >> y;
        Y.push_back(y);
        ssoZ >> z;
        Z.push_back(z);
    }
    int brojac = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
                if(X[i] == Y[j]){
                    for(int k = 0; k < N; k++){
                            if(Z[k] == j + 1){
                                brojac++;
                            }
                    }
                }
        }
    }
    cout << brojac;
    return 0;
}