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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")


/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
template<class T> using ordered_set=tree<T,null_type,less<T>,
rb_tree_tag,tree_order_statistics_node_update>;
 
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007//998244353
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)
#define MAXN 200001
//int fact[300000];
int st[4*MAXN];
int binExp(int x,int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}
int modInv(int i) {return binExp(i,mod-2);}
//int ncr(int n,int r) {return (n>=r?(fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod:0);}
/*void build(int s,int e,int i,int a[])
{    if(s==e){st[i]=a[s];return;}
      int mid=s+(e-s)/2;
    build(s,mid,2*i+1,a);
    build(mid+1,e,2*i+2,a);
    st[i]=st[2*i+1]+st[2*i+2];
}
int query(int s,int e,int i,int a[],int l,int r)
{if(s>e||l>r)return 0;
    if(s>=l&&e<=r)return st[i];
    if(s>r||e<l)return 0;
    int mid=s+(e-s)/2;
    return query(s,mid,2*i+1,a,l,r)+query(mid+1,e,2*i+2,a,l,r);
}

int update(int s,int e,int i,int pos,int val)
{if(s==e&&s==pos)
{st[i]=val;return 0;}

if(s>pos||e<pos)return 0;
int mid=s+(e-s)/2;
update(s,mid,2*i+1,pos,val);
update(mid+1,e,2*i+2,pos,val);
st[i]=st[2*i+1]+st[2*i+2];
}int parent[200000],size[200000];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}*/
signed main()
{
    fast
  int n;
  cin>>n;
  int a[n+1],b[n+1],c[n+1];
  f0(i,0,n)cin>>a[i+1];
   f0(i,0,n)cin>>b[i+1];
    f0(i,0,n)cin>>c[i+1];
    map<int,int>m;
    f0(i,1,n+1)
    {
        m[b[c[i]]]++;
    }
    int ans=0;
    f0(i,1,n+1)ans+=m[a[i]];
    cout<<ans;
   }
// Created by ash_98
 
#include<bits/stdc++.h>
using namespace std;
 
#define mx 200005
#define ll long long
#define mod 1000000007
 
int ar[mx];
char ch[mx];
int n,m,ii,k;
int cnt1[mx],cnt3[mx];
vector<int>g[mx];
 
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		cnt1[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		g[x].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		cnt3[x]++;
	}

	ll re=0;
	for(int i=1;i<=n;i++)
	{
		if(!cnt1[i])continue;
		ll val=0;
		for(int j:g[i])val+=cnt3[j];
		re+=val*cnt1[i];
	}
	printf("%lld\n",re );

}
 
int main()
{
	int t=1;
	//scanf("%d",&t);
	while(t--)solve();
	return 0;
}