#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n;

    map <int, int> x;
    vector <int> y;
    vector <int> z;
    map <int, int> yz;

    for (int i = 0; i < n; i++){
        x[i + 1] = 0;
        yz[i + 1] = 0;
    }
    for (int i = 1; i <= n; i++){
        cin >> k;
        x[k]++;
    }
    for (int i = 1; i <= n; i++){
        cin >> k;
        y.push_back(k);
    }
    for (int i = 1; i <= n; i++){

        cin >> k;
        z.push_back(k);
    }
    sort(z.begin(), z.end());
    for (int i = 0; i < n; i++){
        auto up = upper_bound(z.begin(), z.end(), i + 1);
        auto down = lower_bound(z.begin(), z.end(), i + 1);
        if (up != z.end() && down != z.end())
            yz[y[i]] += up - down;
    }
    long long int sum = 0;
    for (int i = 1; i <= n; i++){
        sum += x[i] * yz[i];
    }
    cout << sum;
    return 0;
}