#define _CRT_DISABLE_PERFCRIT_LOCKS
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> Find(vector<int> v, int n)
{
    vector<int> temp;
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] == n) temp.push_back(i);
    }
    return temp;
}

int main()
{
    FASTIO;
    
    // Nebitno ------------------------
    bool promenjen = false;
    int n, izlaz = 0, checksum;
    vector<int> jela, recepti, scenariji, trazeni, tr2;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        jela.push_back(temp);
    }

    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        recepti.push_back(temp);
    }

    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        scenariji.push_back(temp);
        if (i == 0) { checksum = temp; continue; }
        if (temp == checksum) promenjen = true;
    }
    // ----------------------------------

    for (int i = 0; i < jela.size(); i++)
    {
        trazeni = Find(recepti, jela[i]);
        for (int j = 0; j < trazeni.size(); j++)
        {
            if (promenjen) izlaz += Find(scenariji, trazeni[j] + 1).size();
            else izlaz += n;
        }
    }

    cout << izlaz;
}