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

using namespace std;

void swap(long long int* a, long long int* b) {
    // cout << "&A[i][0] " << a << ", &A[i][1] " << b << endl;
    // cout << "A[i][0] " << *a << ", A[i][1] " << *b << endl;
    long long int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
    // cout << "A[i][0] " << *a << ", A[i][1] " << *b << endl;
}

int partition(vector<long long int>& a, int left, int right) {
    long long int pivot=a[left];
    // cout << "pivot = " << pivot << endl;
    
    int i=left, j=right;
    while(i<j) {
        // cout << "i = " << i;
        while(a[i]<=pivot) i++;
        // cout << " -> " << i << endl;
        // cout << "j = " << j;
        while(a[j]>pivot) j--;
        // cout << " -> " << j << endl;
        if(i<j) swap(&a[i], &a[j]);
    }
    swap(&a[left], &a[j]);
    return j;
}

void quick_sort(vector<long long int>& a, int left, int right) {
    if(left<right) {
        int pivot=partition(a, left, right);

        // cout << "quick_sort(left=" << left << ", pivot=" << pivot << ")" << endl;
        quick_sort(a, left, pivot-1);
        // cout << "quick_sort(pivot+1=" << pivot+1 << ", right=" << right << ")" << endl;
        quick_sort(a, pivot+1, right);
    }
}

int main() {
    int N;
    cin >> N;
    
    vector<vector<long long int> > A(3, vector<long long int>(N));
    for(int i=0; i<3; i++) {
        for(int j=0; j<N; j++) {
            cin >> A[i][j];
        }
        // cout << "&A[i] " << &A[i] << " &A[i][0] " << &A[i][0] << " &A[i][1] " << &A[i][1] << endl;
        // quick_sort(A[i], 0, N-1);
        sort(A[i].begin(), A[i].end());
        // for(int j=0; j<N; j++) {
        //     cout << A[i][j] << " ";
        // }
        // cout << endl;
    }
    
    long long int ans=0;
    // for(int ji=0; ji<N; ji++) {
    //     // cout << "A[0][" << ji << "]=" << A[0][ji];
    //     vector<long long int>::iterator lower_i=upper_bound(A[1].begin(), A[1].end(), A[0][ji]);
    //     for(int jj=distance(A[1].begin(), lower_i); jj<N; jj++) {
    //         // cout << ", A[1][" << jj << "]=" << A[1][jj];
    //         vector<long long int>::iterator lower_j=upper_bound(A[2].begin(), A[2].end(), A[1][jj]);
    //         // cout << ", A[2] num " << N - distance(A[2].begin(), lower_j) << " ";
    //         ans += N - distance(A[2].begin(), lower_j);
    //     }
    //     // cout << endl;
    // }

    for(int i=0; i<N; i++) {
        long long int nowB=A[1][i];
        long long int numA, numC;
        
        // vector<long long int>::iterator iterA;
        // iterA = lower_bound(A[0].begin(), A[0].end(), nowB);
        auto iterA = lower_bound(A[0].begin(), A[0].end(), nowB);
        long long int indxA = distance(A[0].begin(), iterA);
        // numA = indxA;
        numA = (iterA == A[0].end())? N: (indxA + 1) - 1;
        
        // vector<long long int>::iterator iterC;
        // iterC = upper_bound(A[2].begin(), A[2].end(), nowB);
        auto iterC = upper_bound(A[2].begin(), A[2].end(), nowB);
        long long int indxC = distance(A[2].begin(), iterC);
        // numC = N - indxC;
        numC = (iterC == A[2].end())? 0: N - indxC;

        ans += numA*numC;
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3328