#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
const int N = 1e5 + 3;
ll x[N], y[N], z[N];
ll yk[N];
map<ll, ll> recepti;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> x[i];
    for (int i = 1; i <= n; i++) cin >> y[i];
    for (int i = 1; i <= n; i++) cin >> z[i];
    for (int i = 1; i <= n; i++) {
        yk[i] = y[z[i]];
        //dbg(yk[i]);
        recepti[yk[i]]++;
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += recepti[x[i]];
    }

    cout << ans << "\n";
}