/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

#define ll long long 

int main()
{
    ll n;
    cin>>n;
    
    ll a[n];
    ll b[n];
    ll c[n];
    
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    
    for(ll i=0;i<n;i++){
        cin>>b[i];
    }
    
    map<ll,ll>freq;
    
    for(ll i=0;i<n;i++){
        cin>>c[i];
        freq[c[i]]++;
    }
    
    sort(a,a+n);
    
    ll ans=0;
    
    for(auto i:freq){
        ll temp=upper_bound(a,a+n,b[i.first-1])-lower_bound(a,a+n,b[i.first-1]);
        ans+=(temp*i.second);
    }

    cout<<ans<<'\n';
    
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define INF INT_MAX
#define FIO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define mod 1000000007ll
#define forn(i,n) for(int i=0;i<n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define forba(i,b,a) for(int i=b;i>=a;i--)
#define debx(x) cout << #x << ": " << x << endl
#define debxy(x,y) cout << #x << ": " << x << ' ' << #y << ": " << y << endl
#define YESp cout << "YES" << endl
#define NOp cout << "NO" << endl
#define Yesp cout << "Yes" << endl
#define Nop cout << "No" << endl
#define write(a) cout << a << endl
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pq priority_queue

ll fast_exp(ll base, ll power){ll ans=1;while(power){if(power&1)ans=(ans*base)%mod;base=(base*base)%mod;power=power>>1;}return ans%mod;}
ll modInv(ll a,ll p){return fast_exp(a,p-2)%p;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll modFact(ll n){if(n>=mod)return 0;ll result=1;for(ll i = 1; i <= n; i++)result=(result*i)%mod;return result;}

pii moves[] = {{-1, 0}, {1, 0}, {0 ,-1}, {0, 1}};


/****** S ****** X ****** T ****** Y ****** A ****** M ******/


int main() {
  FIO
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", sto");
  int n;
  cin >> n;
  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];

  map<int, ll> mp1, mp2, mp3;
  forn(i, n) mp1[c[i]]++;
  forn(i, n) {
    if(mp1.count(i+1)) mp2[b[i]] += mp1[i+1];
    else mp2[b[i]] += 0;
  }
  forn(i, n) mp3[a[i]]++;
  ll ans = 0;
  for(auto it : mp3) {
    if(mp2.count(it.ff)) ans += (mp2[it.ff] * it.ss);
  }
  cout << ans << endl;
}