#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <int> v1;
    vector <int> v2;
    vector <int> v3;
    vector <int> v4;
    vector <int> v5;
    vector <int> v6;
    for(int i =0;i<n;i++){
        int a;
        cin >>a;
        v1.push_back(a);

    }

    for(int i =0;i<n;i++){
        int a;
        cin >>a;
        v2.push_back(a);

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

    }
    for(int i =0;i<n;i++){
        v4.push_back(0);
    }

    for(int i = 0;i<n;i++){
        v4[v3[i]-1]+=1;
    }


    int maxi = v1[0];
    for(int i = 1;i<n;i++){
        if(v1[i]>maxi){
            maxi = v1[i];
        }
    }
    for(int i =0;i<maxi;i++){
        v5.push_back(0);
        v6.push_back(0);
    }

    for(int i = 0;i<n;i++){
        v5[v1[i]-1]+=1;

    }

    for(int i =0;i<n;i++){
        v6[v2[i]-1]+=v4[i];

    }
    int sum = 0;
    for(int i =0;i<maxi;i++){
        sum+=v6[i]*v5[i];
    }
    cout<<sum;






    return 0;
}