#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

lint zero = 0;

lint modpow(lint a, lint n, lint m = Mod){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;  a *= a;  a %= m;  n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = Mod){
  return modpow(a, m-2, m);
}

lint gcd(lint a, lint b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}         

vi soinsu(lint n){
  vi primes(0); // 素因数
  vi nums(0); // 指数
  vector<bool> nonzero(n, false);
  lint p=2;  lint m = n;
  while(p*p<=n){
    while(m%p==0){
      if(nonzero[p]){ nums[nums.size()-1]++;  m /= p;}
      else{nonzero[p]=true; primes.PB(p); nums.PB(1); m /= p;}
    }
    p++;
  }
  if(m>1){primes.PB(m); nums.PB(1);}
  return nums; // 適宜必要なものを取り出す
}
  //  cout << fixed << setprecision(12);

////////////////////// 
////////////////////

int main(){
  lint n; cin>>n;
  vi acnt(n,0);
  for(lint i=0; i<n; i++){
    lint a; cin>>a; a--;
    acnt[a]++;
  }
  vi bs(n);
  vi bcnt(n,0);
  for(lint i=0; i<n; i++){
    cin>>bs[i]; bs[i]--;
  }
  for(lint i=0; i<n; i++){
    lint c; cin>>c; c--;
    bcnt[bs[c]]++;
  }
  lint ans = 0;
  for(lint i=0; i<n; i++){
    ans += acnt[i]*bcnt[i];
  }
  cout << ans << endl;
}
    

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define sz(x) ((int) (x).size())
#define dbg(x) cerr << #x << "->" << x << "\n";

int gcd(int a, int b) {if (b == 0) return a; return gcd(b, a % b);}
int mod = (int)1e9 + 7;

void solve() {
	int n; cin >> n;
	vector<int> a(n), b(n), c(n);
	forn(i, n)cin >> a[i];
	forn(i, n)cin >> b[i];
	forn(i, n)cin >> c[i];
	vector<int> bc;
	forn(i, n) {
		bc.pb(b[c[i] - 1]);
	}
	map<int, int> ma, mb;
	forn(i, n) ma[a[i]]++;
	forn(i, sz(bc)) mb[bc[i]]++;
	int ans = 0;
	for (auto i : ma) {
		ans += i.second * mb[i.first];
	}
	cout << ans;

}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	forn(i, t)
	solve();
	return 0;
}
