#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>
 
using ll = long long;
using ld = long double;
using namespace std;
using Graph = vector<vector<int>>;
using Priority = priority_queue<int>;

// typedef pair<int,int> P;
#define teisu 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define INF 1e16

ll N,A[100010],B[100010],C[100010];
map<ll,ll> link;
map<ll,ll> cnt;
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        cnt[A[i]]++;
    }
    for(int i=0;i<N;i++) {
        cin >> B[i];
    }
    for(int i=0;i<N;i++) {
        cin >> C[i];
        C[i]--;
        int index = B[C[i]];
        link[index]++;
    }

    ll ans = 0;
    for(int i=1;i<=N;i++){
        ans += cnt[i]*link[i];
    }
    cout << ans << endl;

    return 0;
}                              
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(), x.end()
#define FIO     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define endl "\n"
#define pb push_back
#define mp make_pair
#define re(i,n)        for(int i=0;i<(n);i++)
#define re1(i, k, n) for (int i = k; k < n ? i <= n : i >= n; k < n ? i += 1 : i -= 1)
#define FORD(i,a,b)     for(int i=(a);i>=(b);i--)
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
#define mod 1000000007
//===================================DEBUG TEMPLATE=================================================
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
	cerr << '{';
	__print(x.first);
	cerr << ',';
	__print(x.second);
	cerr << '}';
}
template <typename T>
void __print(const T &x)
{
	int f = 0;
	cerr << '{';
	for (auto &i : x)
		cerr << (f++ ? "," : ""), __print(i);
	cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
	__print(t);
	if (sizeof...(v))
		cerr << ", ";
	_print(v...);
}
//====================================DEBUG TEMPLATE==============================================

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

	int n;
	cin >> n;
	vi a(n + 1), b(n + 1), c(n + 1);
	re(i, n) {
		cin >> a[i + 1];
	}
	re(i, n) {
		cin >> b[i + 1];
	}
	re(i, n) {
		cin >> c[i + 1];
	}
	map<int, int> mp;
	re(i, n) {
		mp[b[c[i + 1]]]++;
	}
	int ans = 0;
	re(i, n) {
		auto it = mp.find(a[i + 1]);
		if (it != mp.end())
			ans += it->ss;
	}
	cout << ans;
	return 0;
}