Scanf.scanf "%d" (fun n ->
    let a = Array.init (n + 1) (fun i -> if i = n then max_int else Scanf.scanf " %d" (fun a -> a)) in
    let b = Array.init n (fun _ -> Scanf.scanf " %d" (fun b -> b)) in
    let c = Array.init (n + 1) (fun i -> if i = n then max_int else Scanf.scanf " %d" (fun c -> c)) in
    Array.sort compare a;
    Array.sort compare b;
    Array.sort compare c;
    let lower arr target =
        let rec bin left right =
            if left = right then left else
                let m = (left + right) / 2 in
                if arr.(m) < target then bin (m + 1) right
                                    else bin left m
        in
        bin 0 n
    in
    let rec loop i acc =
        if i = n then acc else
            let acc = acc + lower a b.(i) * (n - lower c (b.(i) + 1)) in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)