(
  (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: int array) ->
      (
        (arr |> Array.length |> double, 2.) |> System.Math.Log |> ceil |> int,
        arr |> Array.max
      )
      |> fun (limI, maxV) ->
        fun v ->
          if v >= maxV
          then n
          else (
            [1..limI]
            |> 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.Length - 1)
            |> fun (_, i) -> i
          )
  )
  |> fun search ->
    (
      arrB
      |> Array.map (search arrC >> (-) n >> int64)
      |> Array.rev
      |> Array.scan (+) 0L
      |> Array.rev
    )
    |> fun arrBSize ->
      arrA
      |> Array.sumBy (search arrB >> (fun i -> arrBSize.[i]))
|> printfn "%d"
