#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,br=0,naj=0,a=0;cin>>n;vector<ll>vec(n),vec1(n),vec2(n),vec3,vec4;map<int,int>maps1,maps2,maps;
    for(ll i=0;i<n;i++){
        cin>>vec[i];
    }
    for(ll i=0;i<n;i++){
        cin>>vec1[i];
    }
    for(ll i=0;i<n;i++){
        cin>>vec2[i];
    }
    for(ll i=0;i<n;i++){
        maps[vec[i]]++;
    }
    for(ll i=0;i<n;i++){
        maps2[vec2[i]]++;
        a=maps1[vec1[i]]++;
        naj=max(a,naj);
    }
    //cout<<naj;
    for(ll i=0;i<n;i++){
        if(maps[vec1[i]]>0 && maps1[vec1[i]]>0 && maps2[i+1]>0 && maps1[vec1[i]]==1){
             br+=maps[vec1[i]]*maps1[vec1[i]]*maps2[i+1];
             //cout<<maps[vec1[i]]<<maps1[vec1[i]]<<maps2[i+1]<<"a"<<endl;
             //cout<<br<<endl;
        }
    else {
        br+=maps[vec1[i]]*maps2[i+1];
        //br-=(maps1[vec1[i]]*(maps1[vec1[i]]+1))/2;
        //cout<<maps[vec1[i]]<<maps1[vec1[i]]<<maps2[i+1]<<endl;
        //cout<<br<<endl;

    }

    }
    cout<<br;
    return 0;
}