#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin >> n;
    long long broj=0;
    vector<int> X(n);
    vector<pair<int,int>> Ybr(n);
    vector<int> Y(n);
    vector<int> Z(n);
    for(int i=0;i<n;i++)cin >> X[i];
    for(int i=0;i<n;i++){
        cin >> Ybr[i].first;
        Ybr[i].second=i+1;
        Y[i]=Ybr[i].first;
    }
    for(int i=0;i<n;i++)cin >> Z[i];
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    sort(Ybr.begin(),Ybr.end());
    sort(Z.begin(),Z.end());
    long long prethodni=0;
    for(int i=0;i<n;i++){
        if( X[i]==X[i-1] && i>0){
            broj+=prethodni;
            continue;
        }
        prethodni=0;
        auto iter=lower_bound(Y.begin(),Y.end(),X[i]);
        int index = iter - Y.begin();
        while(Ybr[index].first == X[i]){
            prethodni+=count(Z.begin(),Z.end(),Ybr[index].second);
            index++;
        }
        broj+=prethodni;
    }
    cout << broj;
    return 0;
}