#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, ans = 0;
  scanf("%lld", &n);
  ll ca[n + 1], b[n], c;
  for(i = 0; i <= n; ++i) ca[i] = 0;
  for(i = 0; i < n; ++i) scanf("%lld", &c), ca[c]++;
  for(i = 0; i < n; ++i) scanf("%lld", &b[i]);
  for(i = 0; i < n; ++i) scanf("%lld", &c), ans += ca[b[--c]];
  printf("%lld", ans);
  return 0;
}
#pragma region Template  // clang-format off
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, m, n) for (int i = m; i < (int)(n); i++)
#define repe(i, m, n) for (int i = m; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define yesno {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#pragma endregion Template  // clang-format on

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n) cin >> c[i];

  vi cnta(n + 1);
  vi cntb(n + 1);

  rep(i, 0, n) {
    cnta[a[i]]++;
    cntb[b[c[i] - 1]]++;
  }

  ll ans = 0;
  repe(i, 1, n) ans += (ll)cnta[i] * cntb[i];

  cout << ans << endl;
}
