#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<int> vi;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())

void solve()
{
    int n;
    cin >> n;

    vi arr(n), b(n);
    forn(i, n)
    {
        cin >> arr[i];
    }
    forn(i, n)
    {
        cin >> b[i];
    }

    map<int, int> m;

    forn(i, n)
    {
        int x;
        cin >> x;
        --x;
        int val = b[x];
        m[val]++;
    }

    ll cnt = 0;

    forn(i, n)
    {
        if (m.find(arr[i]) != m.end())
        {
            cnt += m[arr[i]];
        }
    }

    cout << cnt << ln;
}
int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    for (int it = 0; it < t; it++)
    {
        // cout << "Case #" << it + 1 << ": ";
        solve();
    }
    return 0;
}
#include <iostream>
#include <map>

using namespace std;

const int MAX = 1e5;

int main() {
  int N; cin >> N;
  map<int, long long> a, bc;
  int B[MAX], C[MAX];
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    a[A]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }

  for (int i = 0; i < N; i++) {
    int C; cin >> C;
    bc[B[--C]]++;
  }

  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += a[i] * bc[i];
  }
  cout << ans << endl;
}
