#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;

int n;

void solve(){
    int x[n],y,z;
    map<int, int> mz;
    map<int, vector<int>> my;
    for(int i=0;i<n;++i)cin>>x[i];
    for(int i=0;i<n;++i){
        cin>>y;
        my[y].pb(i+1);
    }
    for(int i=0;i<n;++i){
        cin>>z;
        mz[z]++;
    }
    ll ans = 0;
    for(int i=0;i<n;++i){
        for(auto j:my[x[i]]){
            ans+=mz[j];
        }
    }
    cout<<ans<<"\n";
}

int main(void){
    cin>>n;
    solve();
    return 0;
}