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

#define int int64_t
#define MOD 998244353
#define inf 9e18
#define tikoo (int) (1e9 + 7)
#define amat(mat, n, m, val) mat.assign(n, vector<int>(m, val))
#define mmat(mat, n, m, val) vector<vector<int>> mat(n, vector<int>(m, val))
#define _mul(a, b) ((a % tikoo) * (b % tikoo)) % tikoo
#define _add(a, b) ((a % tikoo) + (b % tikoo)) % tikoo
#define _sub(a, b) (((a % tikoo) - (b % tikoo)) % tikoo + tikoo) % tikoo
#define _all(a) a.begin(), a.end()
#define print(a) for (auto i : a) cout << i << " "; cout << endl;
#define take(x) int x; cin >> x;

double logn(int n, int base) { return log2(n) / log2(base); }
template<typename T, typename T1> T max(T a, T1 b) { if (b > a) a = b; return a; }
template<typename T, typename T1> T min(T a, T1 b) { if (b < a) a = b; return a; }
int fastpow(int a, int b, int m = tikoo) { int res = 1; a %= m;
    while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; }

void go() {
    ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

signed main() {
    go();
    int t = 1;
    // cin >> t;
    while (t--) {
        take(n);
        map<int, int> a;
        for (int i = 0; i < n; i++) {
            take(x); a[x]++;
        }
        vector<int> b(n);
        for (int i = 0; i < n; i++) {
            cin >> b[i];
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            take(x); x--;
            ans += a[b[x]];
        }
        cout << ans << "\n";
    }
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

#define all(x) x.begin(), x.end()

using namespace std;
//using namespace atcoder;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a.at(i);
  rep(i, n) cin >> b.at(i);
  rep(i, n) cin >> c.at(i);
  vector<int> bc(n, -1);
  rep(i, n) {
    bc.at(i) = b.at(c.at(i) - 1);
  }
  vector<int> cnt(n, 0);
  rep(i, n) {
    cnt.at(bc.at(i) - 1)++;
  }
  ll res = 0;
  rep(i, n) {
    res += cnt.at(a.at(i) - 1);
  }
  cout << res << endl;
  return 0;
}
