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

int main()
{
    ios_base::sync_with_stdio(false);

    unsigned long long n, tmp1, res = 0;
    vector<unsigned long long> X; 
    vector<unsigned long long> Y;
    map<unsigned long long, unsigned long long> mY;
    map<unsigned long long, unsigned long long> mZ;

    cin >> n;
    X.resize(n);
    Y.resize(n);
    for(unsigned long long i = 0; i < n; i++) {
        cin >> X.at(i);
    }
    for(unsigned long long i = 0; i < n; i++) {
        cin >> tmp1;
        Y.at(i) = tmp1;
        mY[tmp1];
        mY[tmp1]++;
    }
    for(unsigned long long i = 0; i < n; i++) {
        cin >> tmp1;
        mZ[Y.at(tmp1 - 1)];
        mZ[Y.at(tmp1 - 1)]++;
    }
    
    for(unsigned long long i = 0; i < n; i++) {
        res += mZ[X.at(i)];
    }
    cout << res << endl;
    return 0;
}