#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll INF=1e9,LINF=1e18,mxN=1e5;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(x) { cerr<<#x<<"="; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }

vector<int> kojiY[mxN+1];
vector<ll> cntX(mxN+1,0),cntZ(mxN+1,0);

void Solve(){
    int N; cin>>N;
    vector<int> X(N+1),Y(N+1),Z(N+1);
    for(int i=1;i<=N;i++){
        cin>>X[i];
        cntX[X[i]]++;
    }
    for(int i=1;i<=N;i++){
        cin>>Y[i];
        kojiY[Y[i]].pb(i);
    }
    for(int i=1;i<=N;i++){
        cin>>Z[i];
        cntZ[Z[i]]++;
    }
    ll res=0;
    for(int i=1;i<=mxN;i++){
        for(int y:kojiY[i]){
            res+=(cntX[i])*(cntZ[y]);
        }
    }
    cout<<res<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        Solve();
    }
    return 0;
}