function Main(input){
    input = input.split("\n");
    var n = input[0];
    var a = input[1].split(" ").map(Number);
    var b = input[2].split(" ").map(Number);
    console.log(Math.abs(p(a)-p(b)))
  }Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
  function p(arr){
      var sum = 0;
      var m = arr.slice().sort();
      for(var i=0;i<arr.length;i++){
          //console.log(m,arr[i])
          var n = m.findIndex((element) => element == arr[i]);
          sum += n*fact(arr.length-1);
        //  console.log(m,n,sum)
          m.splice(n,1);
      }
      //console.log(sum)
      return sum+1;
  }
  function arrsum(arr){
      var sum = 0;
      for(var i=0;i<arr.length;i++){
          sum += arr[i];
      }
      return sum;
  }
  function fact(n){
      if(n!=0)return n*fact(n-1);
      else return 1;
  }