#include <bits/stdc++.h>
using namespace std;
int n,sol;
int jela[100005];
int jela1[100005];
int recepti[100005];
int scenarijip[100005];
int indeks[100005];
int main ()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &jela[i]);
        jela1[jela[i]]++;
    }


    for(int i=1;i<=n;i++){
        scanf("%d",&recepti[i]);
    }
    for(int j=1;j<=n;j++){
        scanf("%d",&scenarijip[j]);
        indeks[scenarijip[j]]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
                if(recepti[j]==i)
                sol+=jela1[i]*indeks[j];
        }
    }
    cout<<sol<<endl;


    return 0;
}