#include <math.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <vector>
#include <cmath>
#include<set>
#include <sstream>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()//配列を全部参照

using namespace std;
using ll = long long int;
using Graph = vector<vector<int>>; // グラフ型
//cin.tie(nullptr); /*高速で入力可能*/
//vector<vector<int>> hako(n, vector<int>(2));
//sort(hako.begin(), hako.end(), [](const vector<int>& alpha, const vector<int>& beta) {return alpha[0] < beta[0]; });


int main() {
	cin.tie(nullptr);
	ll n;
	string s,t;
	ll ans = 0;
	cin >> n;
	vector<int> hako(n);
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(ALL(a));
	rep(i, n) hako[i] = b[c[i] - 1];
	sort(ALL(hako));

	int now = 0;
	rep(i, n) {
		if (i > 0) {
			if (a[i - 1] == a[i]) ans += now;
			else {
				now = 0;
				rep(j, n) {
					if (a[i] == hako[j]) ans++, now++;
					else if (a[i] < hako[j])break;
				}
			}
		}
		else {
			now = 0;
			rep(j, n) {
				if (a[i] == hako[j]) ans++, now++;
				else if(a[i] < hako[j])break;
			}
		}
		
	}

	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define vll vector<long long>
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,s,n) for(int i=s;i<n;i++)
#define sa(v) sort(v.begin(), v.end())
#define sd(v) sort(v.begin(),v.end(), greater<int>())
#define ff first
#define ss second
#define cl(a,b) (a+b-1)/b
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define endl "\n"

using namespace std;

int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;
    vll a(n), b(n),c(n),b1(n+1,0),b2(n+1,0);
    forn(i,n){
        cin>>a[i];
        b1[a[i]]++;
    }
    forn(i,n) cin>>b[i];
    forn(i,n){
        cin>>c[i];
        b2[c[i]]++;
    }
    int ans=0;
    forn(i,n)
        ans+=b1[b[i]]*b2[i+1];
    cout<<ans;
    return 0;
} 