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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, w, c, l;
    c = 0;
    l = 0;
    cin >> n;
    vector <int> x, z;
    vector <pair <int, int>> y;
    for (int i = 0; i < n; i++){
        cin >> w;
        x.push_back(w);
    }
    for (int i = 0; i < n; i++){
        cin >> w;
        y.push_back(make_pair(w, i + 1));
    }
    for (int i = 0; i < n; i++){
        cin >> w;
        z.push_back(w);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(z.begin(), z.end());
    for (int i = 0; i < n; i++){
            for (int j = c; j < n; j++){
                if (x[i] != y[j].first and x[i] > y[j].first){
                    if (x[i] != x[i + 1] or i + 1 == n){
                        c = j;
                        break;
                    }
                    else {
                        break;
                    }
                }
                else if (x[i] == y[j].first){
                    if (binary_search(z.begin(), z.end(), y[j].second)){
                        int s = lower_bound(z.begin(), z.end(), y[j].second) - z.begin();
                        while(z[s] == y[j].second){
                            l++;
                            s++;
                        }
                    }
                    else {
                        continue;
                    }
                }
            }
    }
    cout << l;
    return 0;
}