use std::cmp::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

use std::ascii::AsciiExt;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Write;
use std::iter::Iterator;

use std::fmt;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

#[derive(Copy, Clone)]
struct Modulo {
    n: i64,
}

// precondition: p is prime and mod
fn mod_inverse(a: i64, p: i64) -> i64 {
    if a == 1 {
        1
    } else {
        (1 - p * mod_inverse(p % a, a)) / a + p
    }
}

#[allow(dead_code)]
impl Modulo {
    fn new(n: i64) -> Modulo {
        Modulo {
            n: (n % MODLL + MODLL) % MODLL,
        }
    }

    fn inv(&self) -> Modulo {
        Modulo {
            n: mod_inverse(self.n, MODLL),
        }
    }
}

impl fmt::Debug for Modulo {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.n)
    }
}

impl Add for Modulo {
    type Output = Modulo;
    fn add(self, other: Modulo) -> Modulo {
        Modulo {
            n: (self.n + other.n) % MODLL,
        }
    }
}
impl Add<i32> for Modulo {
    type Output = Modulo;
    fn add(self, other: i32) -> Modulo {
        Modulo {
            n: (self.n + other as i64) % MODLL,
        }
    }
}
impl Add<i64> for Modulo {
    type Output = Modulo;
    fn add(self, other: i64) -> Modulo {
        Modulo {
            n: (self.n + other) % MODLL,
        }
    }
}
impl Sub for Modulo {
    type Output = Modulo;
    fn sub(self, other: Modulo) -> Modulo {
        Modulo {
            n: (self.n - other.n + MODLL) % MODLL,
        }
    }
}
impl Sub<i32> for Modulo {
    type Output = Modulo;
    fn sub(self, other: i32) -> Modulo {
        self - Modulo::new(other as i64)
    }
}
impl Sub<i64> for Modulo {
    type Output = Modulo;
    fn sub(self, other: i64) -> Modulo {
        self - Modulo::new(other)
    }
}
impl Mul for Modulo {
    type Output = Modulo;
    fn mul(self, other: Modulo) -> Modulo {
        Modulo {
            n: (self.n * other.n) % MODLL,
        }
    }
}
impl Mul<i32> for Modulo {
    type Output = Modulo;
    fn mul(self, other: i32) -> Modulo {
        self * Modulo::new(other as i64)
    }
}
impl Mul<i64> for Modulo {
    type Output = Modulo;
    fn mul(self, other: i64) -> Modulo {
        self * Modulo::new(other)
    }
}
impl Div for Modulo {
    type Output = Modulo;
    fn div(self, other: Modulo) -> Modulo {
        self * other.inv()
    }
}
impl Div<i32> for Modulo {
    type Output = Modulo;
    fn div(self, other: i32) -> Modulo {
        self * mod_inverse(other as i64, MODLL)
    }
}
impl Div<i64> for Modulo {
    type Output = Modulo;
    fn div(self, other: i64) -> Modulo {
        self * mod_inverse(other, MODLL)
    }
}

struct Combination {
    fact: Vec<Modulo>,
    ifact: Vec<Modulo>,
}

#[allow(dead_code)]
impl Combination {
    fn new(n: usize) -> Combination {
        let mut fact = vec![Modulo::new(1); n + 1];
        let mut ifact = vec![Modulo::new(1); n + 1];
        for i in 1..n + 1 {
            fact[i] = fact[i - 1] * i as i64;
            ifact[i] = ifact[i - 1] / i as i64;
        }
        Combination {
            fact: fact,
            ifact: ifact,
        }
    }

    /// n!
    fn fact(&self, n: usize) -> Modulo {
        self.fact[n]
    }
    /// 1/n!
    fn inv_fact(&self, n: usize) -> Modulo {
        self.ifact[n]
    }
    /// nCr
    fn comb(&self, n: usize, r: usize) -> Modulo {
        if r > n {
            Modulo::new(1)
        } else {
            self.fact(n) * self.inv_fact(n - r) * self.inv_fact(r)
        }
    }
}

#[derive(PartialEq, Debug, Clone)]
pub struct UnionFindNode {
    pub par: usize,
    pub rank: usize,
}

#[derive(PartialEq, Debug, Clone)]
pub struct UnionFind(pub Vec<UnionFindNode>);

impl UnionFind {
    //初期化
    pub fn new(size: usize) -> UnionFind {
        let mut vec = Vec::new();
        for i in 0..size {
            vec.push(UnionFindNode { par: i, rank: 0 });
        }

        UnionFind(vec)
    }

    //根を求める
    pub fn find(&mut self, x: usize) -> usize {
        if self.0[x].par == x {
            x
        } else {
            let par = self.0[x].par;
            let v = self.find(par);
            self.0[x].par = v;
            v
        }
    }

    //xとyの集合を併合
    pub fn unite(&mut self, x: usize, y: usize) {
        let x = self.find(x);
        let y = self.find(y);
        if x == y {
            return;
        }

        if self.0[x].rank < self.0[y].rank {
            self.0[x].par = y;
        } else {
            self.0[y].par = x;
            if self.0[x].rank == self.0[y].rank {
                self.0[x].rank += 1;
            }
        }
    }

    //xとyが同じ集合に属するか
    pub fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

pub trait LexicalPermutation {
    fn next_permutation(&mut self) -> bool;
    fn prev_permutation(&mut self) -> bool;
}

impl<T> LexicalPermutation for [T]
where
    T: Ord,
{
    fn next_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i - 1] {
            j -= 1;
        }
        self.swap(j, i - 1);
        self[i..].reverse();
        true
    }
    fn prev_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] <= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        self[i..].reverse();
        let mut j = self.len() - 1;
        while j >= i && self[j - 1] < self[i - 1] {
            j -= 1;
        }
        self.swap(i - 1, j);
        true
    }
}

//(小さい,同じ,大きい)
pub fn bound_count<T: Ord>(vec: &Vec<T>, val: &T) -> (usize, usize, usize) {
    let lb = lower_bound(vec, 0, vec.len(), val);
    let ub = upper_bound(vec, 0, vec.len(), val);
    (lb, ub - lb, vec.len() - ub)
}

//より小さい
pub fn less_count<T: Ord>(vec: &Vec<T>, val: &T) -> usize {
    lower_bound(vec, 0, vec.len(), val)
}

//より大きい
pub fn larger_count<T: Ord>(vec: &Vec<T>, val: &T) -> usize {
    vec.len() - upper_bound(vec, 0, vec.len(), val)
}

//同じ
pub fn eq_count<T: Ord>(vec: &Vec<T>, val: &T) -> usize {
    upper_bound(vec, 0, vec.len(), val) - lower_bound(vec, 0, vec.len(), val)
}

//vecは昇順ソート済み
//以上
pub fn lower_bound<T: Ord>(vec: &Vec<T>, mut first: usize, mut last: usize, val: &T) -> usize {
    let mut mid;
    while last - first > 1 {
        mid = (first + last) / 2;
        if &vec[mid] < val {
            first = mid;
        } else {
            last = mid;
        }
    }
    if &vec[first] < val {
        last
    } else {
        first
    }
}

//より大きい
pub fn upper_bound<T: Ord>(vec: &Vec<T>, mut first: usize, mut last: usize, val: &T) -> usize {
    let mut mid;
    while last - first > 1 {
        mid = (first + last) / 2;
        if &vec[mid] <= val {
            first = mid;
        } else {
            last = mid;
        }
    }
    if &vec[first] <= val {
        last
    } else {
        first
    }
}

fn main() {
    input! {
        n: usize,
        a:[i64;n],
        b:[i64;n],
        c:[i64;n],
    }

    let mut vec_a = a;
    let vec_b = b;
    let mut vec_c = c;

    vec_a.sort();
    vec_c.sort();

    let mut ans = 0;
    for j in 0..n {
        let a_max = lower_bound(&vec_a, 0, n, &vec_b[j]);
        let c_min = upper_bound(&vec_c, 0, n, &vec_b[j]);

        if a_max == 0 && n-c_min ==0{
            break;
        }
        ans += a_max * (n-c_min);

    } 
    println!("{}", ans);
}


Measured memory_bytes: 8444