(
  (stdin.ReadLine() |> int),
  (stdin.ReadLine() |> fun x -> x.Split(' ') |> Array.map int |> Array.sort),
  (stdin.ReadLine() |> fun x -> x.Split(' ') |> Array.map int |> Array.sort),
  (stdin.ReadLine() |> fun x -> x.Split(' ') |> Array.map int |> Array.sort)
)
|> fun (n, arrA, arrB, arrC) ->
  (
    fun arr v ->
      (System.Math.Log((arr |> Array.length |> double), 2.) |> ceil |> int)
      |> fun limit ->
        [1..limit]
        |> List.fold (
          fun (li, ri) _ ->
            if li = ri then (li, ri) else (
              li + (ri - li) / 2
              |> fun mi ->
                match compare v arr.[mi] with
                | -1 -> (li, mi)
                | _ -> (mi + 1, ri)
            )
        ) (0, (arr |> Array.length) - 1)
        |> fun (_, i) -> i
  )
  |> fun search ->
    (
      arrB |> Array.max,
      arrC |> Array.max
    )
    |> fun (maxB, maxC) ->
      (
        arrB
        |> Array.filter (fun x -> x < maxC)
        |> Array.map (search arrC >> (-) n)
        |> Array.rev
        |> Array.scan (+) 0
        |> Array.rev
      )
      |> fun arrBSize ->
        arrA
        |> Array.filter (fun x -> x < maxB)
        |> Array.sumBy (search arrB >> (fun i -> arrBSize.[i]) >> int64)
|> printfn "%d"
