#include <bits/stdc++.h>

using namespace std;

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

    }

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

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

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

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


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

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

    }

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

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






    return 0;
}