let n = read_int()
let f () = Array.init n (fun _ -> Scanf.scanf " %d" (fun i -> i))
let a = f ()
let b = f ()
let c = f ()

let rec f j ans =
  if j = n then ans
  else
    let rec g l r =
      if l = r then l + 1
      else
        let m = (l + r + 1) / 2 in
        if a.(m) < b.(j) then g m r
        else g l (m - 1) in
    let rec h l r =
      if l = r then n - l
      else
        let m = (l + r) / 2 in
        if b.(j) < c.(m) then h l m
        else h (m + 1) r in
    let i = g ~-1 (n - 1) in
    let k = h 0 n in
    f (j + 1) (ans + i * k)

let () =
  Array.sort (fun x y -> x - y) a;
  Array.sort (fun x y -> x - y) c;
  let ans = f 0 0 in
  Printf.printf "%d\n" ans
