#include <bits/stdc++.h>
using namespace std;
int n,ybrojac,zbrojac,ukbrojac,autisticanbrojac;
int x[100005];int y[100005]; int z[100005];
int main (){
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>x[i];
    }

    for(int i=1; i<=n; i++){
        cin>>y[i];
    }

    for(int i=1; i<=n; i++){
        cin>>z[i];
    }

    for(int i=1; i<=n; i++){
        autisticanbrojac=0;
        ybrojac=0;
        zbrojac=0;
        for(int j=1; j<=n; j++){
            if (x[i]==y[j]){
                ybrojac++;
                for (int k=1; k<=n;k++ ){
                    if (y[j]+1==z[k]){
                        zbrojac++;
                    }
                }
            }
        }
                if (zbrojac>0 and ybrojac>0)
                ukbrojac+=(zbrojac*ybrojac);
                if(ybrojac>1)
                    ukbrojac+=ybrojac;
              //  cout<<"i "<<i<<" x[i]"<<x[i]<<" ybrojac "<<ybrojac<<" zbrojac "<<zbrojac<<" ukbrojac "<<ukbrojac<<endl;
    }


    cout<<ukbrojac<<endl;


return 0;
}