#include <bits/stdc++.h>

using namespace std;

int main()
{
    // O(2n) ??
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n+13];
    vector<int> cnt(n+13, 0);
    map<int, vector<int>> m;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) {
        int u;
        cin >> u;
        m[u].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        int u;
        cin >> u;
        cnt[u]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int k = a[i];
        for (auto i : m[k]) {
            ans += cnt[i];
        }
    }
    cout << ans << '\n';
    return 0;
}