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: n = int(input())
  p = [int(i) - 1 for i in input().split()]
  q = [int(i) - 1 for i in input().split()]
  
  fact = [1] * 10
  for i in range(2, 10):
      fact[i] = fact[i - 1] * i
  
  index1 = 1
  l = [i for i in range(n)]
  while len(p) > 0:
      i = p.pop(0)
      l.remove(i)
      cnt = len([k for k in l if k < i])
      index1 += cnt * fact[len(l)]
  
  
  index2 = 1
  l = [i for i in range(n)]
  while len(q) > 0:
      i = q.pop(0)
      l.remove(i)
      cnt = len([k for k in l if k < i])
      index2 += cnt * fact[len(l)]
  
  print(abs(index1 - index2))
  
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"}]