#include <bits/stdc++.h>

using namespace std;

int main()
{
    // O(2n) ??
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n+13], b[n+13];
    for (int i = 1; i <= n; ++i)    cin >> a[i];
    for (int i = 1; i <= n; ++i)    cin >> b[i];
    vector<int> cnt1(n+13, 0), cnt2(n+13, 0);
    for (int i = 1; i <= n; ++i) {
        int u;
        cin >> u;
        cnt1[u]++;
    }
    for (int i = 1; i <= n; ++i) {
        cnt2[b[i]] += cnt1[i];
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += cnt2[a[i]];
    }
    cout << ans << '\n';
    return 0;
}