output_description: Print |a - b|.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      P_1 P_2 ... P_N
      Q_1 Q_2 ... Q_N
attempt: bit = [0] * 9
  fa = [1] * 9
  for n in range(1, 9):
      fa[n] = fa[n - 1] * n
  
  
  def up(id):
      while id < 9:
          bit[id] += 1
          id += id & (-id)
  
  
  def qr(id):
      res = 0
      while id:
          res += bit[id]
          id -= id & (-id)
      return res
  
  
  x = int(input())
  s = list(map(int, input().split()))
  z = list(map(int, input().split()))
  
  v = ""
  
  for n in s:
      a = qr(n)
      vl = n - 1 - a
      v += str(vl)
      up(n)
  v = v[::-1]
  r1 = 0
  for n in range(len(v)):
      r1 += int(v[n]) * fa[n]
  
  r2 = 0
  v = ""
  bit = [0] * 9
  for n in z:
      a = qr(n)
      vl = n - 1 - a
      v += str(vl)
      up(n)
  v = v[::-1]
  for n in range(len(v)):
      r2 += int(v[n]) * fa[n]
  
  print(abs(r1 - r2))
  
problem_description: Statement
  
  We have two permutations P and Q of size N (that is, P and Q are both
  rearrangements of (1,~2,~...,~N)).
  
  There are N! possible permutations of size N. Among them, let P and Q be the
  a-th and b-th lexicographically smallest permutations, respectively. Find |a -
  b|.
samples: [{"input": "3\n    1 3 2\n    3 1 2", "output": "3\n    \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n    7 3 5 4 2 1 6 8\n    3 8 2 5 4 6 7 1", "output": "17517\n    \n\n* * *"}, {"input": "3\n    1 2 3\n    1 2 3", "output": "0"}]