#include <iostream>
#include <vector>

using namespace std;

int main()
{
    long long unsigned N = 0, br, brMogucih = 0;
    vector<long long unsigned> jela, recepti, scenariji, podudRecepti;

    cin >> N;
    for(long long unsigned i = 0; i < N; i++)
    {
        cin >> br;
        jela.push_back(br);
    }
    for(long long unsigned i = 0; i < N; i++)
    {
        cin >> br;
        recepti.push_back(br);
    }
    for(long long unsigned i = 0; i < N; i++)
    {
        cin >> br;
        scenariji.push_back(br);
    }

    for(long long unsigned i = 0; i < N; i++)
    {
        podudRecepti.clear();

        for(long long unsigned j = 0; j < N; j++)
        {
            if(jela[i] == recepti[j])
            {
                podudRecepti.push_back(j + 1);
            }
        }
        for(long long unsigned x = 0; x < podudRecepti.size(); x++)
        {
            for(long long unsigned y = 0; y < N; y++)
            {
                if(podudRecepti[x] == scenariji[y])
                {
                    brMogucih++;
                }
            }
        }
    }

    cout << brMogucih;

    return 0;
}