#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
vector<long> a(1000000, 0);
vector<long> b(1000000, 0);
vector<long> c(1000000, 0);
int main()
{
    long n;
    long t;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> t;
        a.at(t) += 1;
    }
    for (int i=0; i<n; i++)
    {
        cin >> t;
        b.at(i+1) = t;
    }
    long ans = 0;
    for (int i=0; i<n; i++)
    {
        cin >> t;
        ans += a.at(b.at(t));
    }
    cout << ans << endl;
}
#include <iostream>

#include <cmath>
#include <cstring>

#include <map>
#include <set>
#include <vector>

#include <algorithm>
#include <bitset>
#include <complex>
#include <numeric>
#include <string>
#include <utility>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using g = vector<vector<int>>;
using vi = vector<int>;

const int INF = 1001001001;

int main()
{
    int n;
    cin>>n;
    vi a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    vi cnt(n + 1);
    rep(i, n) cnt[a[i]]++;
    ll ans = 0;
    rep(j, n) ans += cnt[b[c[j] - 1]];
    cout << ans << endl;

    return 0;
}