#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin>>N;
  
  vector<int> A(100001),B(100001),C(100001);
  vector<int> count(100001);
  
  for(int i=0;i<N;i++){
  	cin>>A.at(i);
  }
  
  for(int i=0;i<N;i++){
  	cin>>B.at(i);
  }
  
  for(int i=0;i<N;i++){
  	cin>>C.at(i);
  }
 
  for(int j=0;j<N;j++){
  	count.at(B.at(C.at(j)-1))+=1;
  }
  
  long long ans=0;
  for(int i=0;i<N;i++){
  	ans+=count.at(A.at(i));
  }
  cout<<ans<<endl;
  
  return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define int long long
#define reset(x) memset(x,0,sizeof(x))
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define PI 3.1415926535897932384626433832795
#define INF 1000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int MAXN = 100005;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    int n; cin >> n;
    int arr[n + 1], brr[n + 1], crr[n + 1];

    vector<vector<int>> equal(n + 1, vector<int>());
    int exist[n + 1];
    reset(exist);
    for (int i = 0; i < n; i++)
    {
    	cin >> arr[i + 1];
    	exist[arr[i + 1]]++;
    }
    for (int i = 0; i < n; i++)
    {
    	cin >> brr[i + 1];
    	equal[brr[i + 1]].pb(i + 1);
    }
    int num_time[n + 1];
    reset(num_time);
    for (int i = 0; i < n; i++)
    {
    	cin >> crr[i + 1];
    	num_time[crr[i + 1]]++;
    }
    int sum = 0;
    bool used[n + 1]; reset(used);
    for (int i = 1; i <= n; i++)
    {
    	int tmp = 0;
    	if (used[arr[i]] == true)
    	{
    		continue;
    	}
    	for (int x : equal[arr[i]])
    	{
    		tmp += num_time[x];
    	}
    	sum += (tmp * exist[arr[i]]);
    	used[arr[i]] = true;
    }
    cout << sum;
}
