#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, x, y, z, nizx[100100], nizy[100100], nizz[100100], a, br = 0;
    cin >> n;
    for(int i = 1; i < n+1; i++)
    {
        cin >> x;
        nizx[i] = x;
    }
    for(int i = 1; i < n+1; i++)
    {
        cin >> y;
        nizy[i] = y;
    }
    for(int i = 1; i < n+1; i++)
    {
        cin >> z;
        nizz[i] = z;
    }
    for(int i = 1; i < n+1; i++)
    {
        a = nizx[i];
        vector<int> v;
        int* ptr = std::find(std::begin(nizy), std::end(nizy), a);
        while (ptr != std::end(nizy))
        {
            int ind, b = 0;
            ind  = std::distance(std::begin(nizy), ptr);
            b = count(nizz, nizz+n+1, ind);
            //cout << ind << " " << b << endl;
            br += b;
            ptr = std::find(ptr + 1, std::end(nizy), a);
        }
            /*
            cout << std::distance(std::begin(nizy), ptr) << endl;
            v.push_back(std::distance(std::begin(nizy), ptr));
            ptr = std::find(ptr + 1, std::end(nizy), a);

        }

        for(int j = 1; j < n+1; j++)
            if(nizy[j] == a)
        {
            for(int k = 1; k < n+1; k++)
                if(j == nizz[k])
                    br++;
        }*/
    }
    cout << br;
    return 0;

}