#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int main(void) {
    long long int n;
    cin >> n;
    Vec<long long int> a(n);
    Vec<long long int> b(n);
    Vec<long long int> c(n);
    FOR (i, 0, n) {
        cin >> a[i];
    }
    FOR (i, 0, n) {
        cin >> b[i];
    }
    FOR (i, 0, n) {
        cin >> c[i];
    }
    VSORT(a);
    VSORT(b);
    VSORT(c);
    Vec<long long int> ab(n, 0);
    Vec<long long int> bc(n, 0);

    // ab
    long long int as = n - 1;
    long long int bs = n - 1;
    while (1) {
        if (a[as] < b[bs]) {
            ab[as]++;
            bs--;
        } else {
            as--;
        }

        if (as == 0) {
            while (1) {
                if (bs == -1) {
                    break;
                }
                if (a[as] < b[bs]) {
                    ab[0]++;
                    bs--;
                } else {
                    break;
                }
            }
            break;
        }

        if (bs == 0) {
            while (1) {
                if (as == -1) {
                    break;
                }
                if (b[bs] > a[as]) {
                    ab[as]++;
                    break;
                } else {
                    as--;
                }
            }
            break;
        }
    }


    // bc
    bs = n - 1;
    long long int cs = n - 1;
    while (1) {
        if (b[bs] < c[cs]) {
            bc[bs]++;
            cs--;
        } else {
            bs--;
        }
        if (bs == 0) {
            while (1) {
                if (cs == -1) {
                    break;
                }
                if (b[bs] < c[cs]) {
                    bc[0]++;
                    cs--;
                } else {
                    break;
                }
            }
            break;
        }

        if (cs == 0) {
            while (1) {
                if (bs == -1) {
                    break;
                }
                if (c[cs] > b[bs]) {
                    bc[bs]++;
                    break;
                } else {
                    bs--;
                }
            }
            break;
        }
    }

    /*
       FOR (i, 0, n) {
       cout << ab[i] << " ";
       }
       cout << endl;
       FOR (i, 0, n) {
       cout << bc[i] << " ";
       }
       cout << endl;
     */

    REFOR (i, n - 2, 0) {
        ab[i] += ab[i + 1];
    }

    REFOR (i, n - 2, 0) {
        bc[i] += bc[i + 1];
    }
    REFOR (i, n - 2, 0) {
        bc[i] += bc[i + 1];
    }

    /*
       FOR (i, 0, n) {
       cout << a[i] << " ";
       }
       cout << endl;
       FOR (i, 0, n) {
       cout << b[i] << " ";
       }
       cout << endl;
       FOR (i, 0, n) {
       cout << c[i] << " ";
       }
       cout << endl;

       FOR (i, 0, n) {
       cout << ab[i] << " ";
       }
       cout << endl;
       FOR (i, 0, n) {
       cout << bc[i] << " ";
       }
       cout << endl;
     */

    long long int ans = 0;
    FOR (i, 0, n) {
        if (ab[i] == 0) {
            break;
        } else {
            ans += bc[n - ab[i]];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4224