#define _CRT_DISABLE_PERFCRIT_LOCKS
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#include <iostream>
#include <vector>
#include <map>
#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 ------------------------
    int n, izlaz = 0;
    vector<int> jela, trazeni, tr2;
    map<int, vector<int>> recepti, scenariji;
    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;

        if (recepti.find(temp) == recepti.end())
        {
            recepti.insert({ temp, {i} });
        }
        else
        {
            recepti[temp].push_back(i);
        }
    }

    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;

        if (scenariji.find(temp) == scenariji.end())
        {
            scenariji.insert({ temp, {i} });
        }
        else
        {
            scenariji[temp].push_back(i);
        }
    }
    // ----------------------------------

    for (int i = 0; i < jela.size(); i++)
    {
        if (recepti.find(jela[i]) == recepti.end()) continue;
        int jelo = jela[i];
        vector<int> recepti2 = recepti[jelo];

        for (int j = 0; j < recepti2.size(); j++)
        {
            izlaz += scenariji[recepti2[j] + 1].size();
        }
    }

    cout << izlaz;
}