import scala.io.StdIn

object Main extends App {

  //
  // std in
  //

  val n = StdIn.readLong()
  val as = StdIn.readLine().split(" ").map(_.toLong)
  val bs = StdIn.readLine().split(" ").map(_.toLong)
  val cs = StdIn.readLine().split(" ").map(_.toLong)

  //
  // main
  //

  val bsForAs: Array[Long] = as.flatMap(a => aCandidates(a, bs, n))

  val bMap = bs.distinct.map(b => bCandidates(b, cs, n)).toMap

  println(bsForAs.toSeq)
  println(bMap)
  println(bsForAs.map(b => bMap(b)).sum)

  //
  // functions
  //

  private def aCandidates(a: Long, bs: Array[Long], n: Long): Array[Long] = bs.slice(bin_search(bs, a, 0, n - 1), n)

  private def bCandidates(b: Long, cs: Array[Long], n: Long): (Long, Long) = (b, n - bin_search(cs, b, 0, n - 1))

  private def bin_search(xs: Array[Long], x: Long, lSide: Long, rSide: Long): Long = {
    if (rSide < lSide) lSide
    else {
      val mid = lSide + (rSide - lSide) / 2
      if (x < xs(mid)) bin_search(xs, x, lSide, mid - 1)
      else bin_search(xs, x, mid + 1, rSide)
    }
  }
}
