let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare
let b = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare
let c = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let rec drop_while f = function
  | (_, []) -> (0, [])
  | (i, x :: xs) as tpl -> if f x then drop_while f (i - 1, xs) else tpl

let rec loop ans a b c = match b with
  | [] -> ans
  | x :: xs ->
    let a = drop_while (fun i -> i < x) a in
    let c = drop_while (fun i -> i <= x) c in
    loop (ans + (n - fst a) * (fst c)) a xs c

let () = Printf.printf "%d\n" @@ loop 0 (n, a) b (n, c)