#include <iostream>
#include <vector>
using namespace std;

int main(){

    int n; cin >> n;

    vector<int> jela(n);
    vector<int> recepti(n);
    vector<int> scenariji(n);

    for(int i=0; i<n; i++){
        int val; cin >> val;
        jela[val-1]++;
    }
    for(int i=0; i<n; i++){
        cin >> recepti[i];
    }
    for(int i=0; i<n; i++){
        int val; cin >> val;
        scenariji[val-1]++;
    }

    int solution = 0;
    for(int i=0; i<n; i++){
        solution += jela[recepti[i]-1] * scenariji[i];
    }

    cout << solution;

}