#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
	ll N, ai;
	cin >> N;
	vector<ll> A(N, 0), B(N, 0), C(N, 0);
	for (ll i = 0; i < N; i++) {
		cin >> ai;
		A[ai - 1]++;
	}
	for (ll i = 0; i < N; i++) cin >> B[i];
	for (ll i = 0; i < N; i++) cin >> C[i];
	vector<ll> BC(N, 0);
	for (ll i = 0; i < N; i++) {
		BC[B[C[i] - 1] - 1]++;
	}
	//for (ll i = 0; i < N; i++) cout << BC[i] << " ";
	//cout << endl;
	ll count = 0;
	for (ll i = 0; i < N; i++) {
		count += A[i] * BC[i];
	}
	cout << count << endl;
}

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a, ll b) {return (a + (b - 1)) / b;}
ll myfloor(ll a, ll b) {return a / b;}

int main() {
	//input
	ll N; cin >> N;

	vector<ll> A(N);
	REP(i, N) {
		cin >> A[i];
		A[i]--;
	}
	vector<ll> B(N);
	REP(i, N) {
		cin >> B[i];
		B[i]--;
	}
	vector<ll> C(N);
	REP(i, N) {
		cin >> C[i];
		C[i]--;
	}


	//calculation

	vector<ll> cnt_A(N, 0), cnt_B(N, 0);
	REP(i, N) {
		cnt_A[ A[i] ]++;
		cnt_B[ B[ C[i] ] ]++;
	}

	ll output = 0;
	REP(i, N) output += cnt_A[i] * cnt_B[i];

	//output
	cout << output << endl;


	return 0;
}
