#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::cmp::Ordering;
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
        b: [i64; n],
        c: [i64; n],
    }
    let mut a = a;
    let mut b = b;
    let mut c = c;
    a.sort();
    b.sort();
    c.sort();
    let mut a_num = vec![0;n];
    //let mut now_b = 0;
    for ai in 0..n {
        let bi = b.upper_bound(&a[ai]);
        a_num[ai] = n - bi;
        /*
        for bi in now_b..n {
            if a[ai] < b[bi] {
                a_num[ai] = n - bi;
                now_b = bi;
                println!("{} {}", tmp, bi);
                break;
            }
        }
        */
    }
    let mut b_num = vec![0;n];
    //let mut now_c = 0;
    for bi in 0..n {
        let ci = c.upper_bound(&b[bi]);
        b_num[bi] = n - ci;
        /*
        for ci in now_c..n {
            if b[bi] < c[ci] {
                b_num[bi] = n - ci;
                now_c = ci;
                break;
            }
        }
        */
    }
    let mut b_des = vec![0; n];
    let mut sum = 0;
    for j in (0..n).rev() {
        sum += b_num[j];
        b_des[j] = sum;
    }

    let mut num = 0;
    for i in 0..n {
        if a_num[i] != 0 {
            num += b_des[n-a_num[i]];
        }
    }
    println!("{}", num);
}

Measured memory_bytes: 14456