#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define ff(i,a,b) for(int (i) = (a);(i)<(b);(i)++)
#define fff(i,a,b) for(int (i) = (a);(i)<=(b);(i)++)

using namespace std;
using namespace __gnu_pbds;

int main()
{
    FAST;
    long long int N; cin>>N;
    long long int X[N+5];
    long long int Y[N+5];
    long long int Z[N+5];
    long long int counterX[N+5];
    long long int counterZ[N+5];
    fff(i,1,N){
        cin>>X[i];
    }
    fff(i,1,N){
        cin>>Y[i];
    }
    fff(i,1,N){
        cin>>Z[i];
    }
    fff(i,1,N){
        counterX[i]=0;
        counterZ[i] = 0;
    }
    fff(i,1,N){
        counterX[X[i]]++;
        counterZ[Y[Z[i]]]++;
    }
    long long int s = 0;
    fff(i,1,N){
        s+=counterX[i]*counterZ[i];
    }
    cout<<s<<endl;
    return 0;
}