#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;

const ll MX = 1e18;
const long double PI = acos(-1);

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline vector<T> divisor(T n) {
    vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

template<class T> inline vector<pair<T, T>> prime_factor(T n) {
    vector<pair<T, T>> ret;
    for (T i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        T tmp = 0;
        while (n % i == 0) {
            tmp++;
            n /= i;
        }
        ret.push_back(make_pair(i, tmp));
    }
    if (n != 1) ret.push_back(make_pair(n, 1));
    return ret;
}

int main()
{
    int n; cin >> n;
    vector<int> a(n); rep(i, n){cin >> a[i]; a[i]--;} 
    vector<int> b(n); rep(i, n){cin >> b[i]; b[i]--;}
    vector<int> c(n); rep(i, n){cin >> c[i]; c[i]--;}

    vector<int> bc(n); rep(i, n) bc[b[c[i]]] += 1;
    ll count = 0;
    rep(i, n)
    {
        count += bc[a[i]];
    }

    pri(count);
    return 0;
}

#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N], cnt[N], cnt2[N];
//map<int, int> mp, mp2;


int main(){
	ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;

	for(int i = 1; i <= n; i++){
		cin >> a[i];
		cnt[a[i]]++;
		//mp[a[i]]++;
	}

	for(int i = 1; i <= n; i++){
		cin >> b[i];
	}

	int x;
	for(int i = 1; i <= n; i++){
		cin >> x;
		cnt2[b[x]]++;
		//mp2[b[x]]++;
	}

	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += (cnt[i] * 1LL * cnt2[i]);
	}
	cout << ans << '\n';


	/*
	for(auto i: mp){
		auto it = mp2.find(i.first);
		if(it != mp2.end()){
			ans += (i * (*it)) << '\n';
		}
	}
	*/

	return 0;	
}