#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int jela[n + 1];
    int recept[n + 1];
    int scenario[n + 1];
    long long int counter = 0;
    int valuesS[100100];
    int valuesR[100100];
    int valuesJ[100100];
    int values1[100100];
    //declaring starting values
    for (int i = 0; i < 100100; i++){
        valuesS[i] = 0;
        valuesR[i] = 0;
        valuesJ[i] = 0;
        values1[i] = 0;
    }
    //input 
    for (int i = 1; i <= n; i++){
        cin >> jela[i];
        valuesJ[jela[i]]++;
    }
    for (int i = 1; i <= n; i++){
        cin >> recept[i];
        valuesR[recept[i]]++;
    }
    for (int i = 1; i <= n; i++){
        cin >> scenario[i];
        valuesS[recept[scenario[i]]]++;
    }
    
    //calculation
    for (int i = 1; i <= 100100; i++){
        if (valuesR[i] > 1){
            valuesR[i] = 1;
        }
        values1[i] = valuesJ[i] * valuesR[i];
    }
    
    for (int i = 1; i <= 100100; i++){
        counter += valuesS[i] * values1[i];
    }
    
    cout << counter;
}