open Printf
open Scanf

let () =
  let n = scanf "%d " (fun x -> x) in
  let tbl = Array.init 3 (fun _ ->
                          let a = Array.init n (fun _ ->
                                                let v = scanf "%d " (fun x -> x) in v
                                               ) in Array.sort compare a; a) in
  let ct = Array.make_matrix 3 n 0 in
  let rec loop i j =
    if i = 3 then Array.fold_left (+) 0 ct.(2)
    else if j = n then loop (i+1) 0
    else if i = 0 then (ct.(0).(j) <- 1; loop i (j+1))
    else let rec loop2 k =
           if k = n || tbl.(i).(j) <= tbl.(i-1).(k) then ()
           else (ct.(i).(j) <- ct.(i-1).(k) + ct.(i).(j);
                 loop2 (k+1)) in
         loop2 0;
         loop i (j+1) in
  loop 0 0 |> printf "%d\n"
