#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int binarna(vector<int> a, int b){
    int d = 0, g = a.size()-1, s = (d+g)/2, rez = 1;

    while(a[s] != b && d != g){
        if(b > a[s]) d = s+1;
        else g = s-1;

        s = (d+g)/2;
    }
    if(a[s] != b) return 0;

    for(int i = s+1; i < a.size(); i++){
        if(a[i] == b) rez++;
    }

    for(int i = s-1; i >= 0; i--){
        if(a[i] == b) rez++;
    }

    return rez;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, br = 1, rez = 0;
    cin >> n;

    vector<int> a(n), b(n), c(n);

    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];

    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    for(int i = 0; i < n; i++){
        if(i != n-1 && c[i] == c[i+1]) br++;
        else{
            rez += br*binarna(a, b[c[i]-1]);
            br = 1;
        }
    }

    cout << rez;
}