#include <iostream>
using namespace std;
#define MAX_N 1000010
#define int long long
int a[MAX_N],b[MAX_N],c[MAX_N],n;
int a2[MAX_N],b2[MAX_N],c2[MAX_N];
signed main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        a2[a[i]]++;
    }
    for(int i = 1;i <= n;i++){
        cin >> b[i];
        c2[i] = a2[b[i]];
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        cin >> c[i];
        ans += c2[c[i]];
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
    int64_t N; cin >> N;
    vector<int64_t> A(N);
    rep(i, N) cin >> A.at(i);
    vector<int64_t> B(N);
    rep(i, N) cin >> B.at(i);
    vector<int64_t> C(N);
    rep(i, N) {
        cin >> C.at(i);
        C.at(i)--;
    }
    vector<int64_t> X(N);
    rep(i, N) X.at(i) = B.at(C.at(i));
    sort(A.begin(), A.end());
    sort(X.begin(), X.end());
    int64_t xi = 0, cA = 0, cX = 0, ans = 0;
    rep(i, N) {
        if (A.at(i) < X.at(xi)) continue;
        while (A.at(i) > X.at(xi) && xi < N - 1)
        {
            xi++;
        }
        if (A.at(i) == X.at(xi)) {
            if (i < N - 1 && A.at(i+1) == X.at(xi)) {
                cA++; continue;
            }
            while (xi < N - 1 && A.at(i) == X.at(xi+1)) {
                cX++; xi++;
            }
            cA++; cX++; ans += cA * cX; cA = 0; cX = 0;
        }
    }
    cout << ans << endl;
}