object Main extends App{
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  val n = readInt
  val a = readLine.split(" ").map(_.toInt).toList
  val b = readLine.split(" ").map(_.toInt).toList
  
  def dicNum(x:List[Int]):Long ={
    def dicNumRe(acc:Long,x:List[Int]):Long =
    x match{
      case Nil => acc
      case _ => dicNumRe(acc + (x.filter(_ < x.head).length)*((1 to (x.length - 1)).product) , x.tail)
    }
    dicNumRe(0,x)
  }
  
  println(math.abs(dicNum(a)-dicNum(b)).toString)
}
