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

int  main() {
  int n;
  scanf("%d\n", &n);
  vector<int> a(n), b(n), c(n);
  vector<long long> d(n + 1, 0), e(n + 1, 0), f(n + 1, 0);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a.at(i));
    d.at(a.at(i))++;
  }
  for(int i = 0; i < n; i++) {
    scanf("%d", &b.at(i));
    e.at(b.at(i))++;
  }
  for(int i = 0; i < n; i++) {
    scanf("%d", &c.at(i));
    f.at(b.at(c.at(i) - 1))++;
  }
  
  long long sum = 0;
  for(int i = 1; i <= n; i++) {
    sum += d.at(i) * f.at(i);
  }
  
  printf("%lld\n", sum);
}
#include <bits/stdc++.h>
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define dbgpr(x) cout << #x << " is " << x << endl
#define endl '\n'
using namespace std; using ll = long long; using ii = pair<int,int>;
void solution(); int main() {ios::sync_with_stdio(0); cin.tie(0); solution();}
const int N = 100003;
int n, a[N], b[N], c[N];
int cnt[N];

void input() {
    cin >> n;
    REP(i,1,n) cin >> a[i];
    REP(i,1,n) cin >> b[i];
    REP(i,1,n) cin >> c[i];
}
void solution() {
    input();
    REP(i,1,n) ++cnt[b[c[i]]];
    ll ans = 0;
    REP(i,1,n) {
        ans += cnt[a[i]];
    }
    cout << ans;
}